-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest.rb
executable file
·62 lines (53 loc) · 1.48 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
require 'shellwords'
module DSL
module Constants
Backslash = '\\'
Enter = 'Enter'
Space = 'Space'
end
class << self
def escape(string)
Shellwords.shellescape(string)
end
end
class Session
WAIT_TIMEOUT = 5
def initialize(name)
@name = name
end
def send_keys(*args)
escaped = args.map { |arg| DSL.escape(arg) }
%x{tmux send-keys -t #{@name} #{escaped.join(' ')}}
end
def wait_for(pattern)
buffer = nil
start = Time.now
while (Time.now - start < WAIT_TIMEOUT)
%x{tmux capture-pane -t #{@name}}
buffer = %x{tmux show-buffer}
%x{tmux delete-buffer}
return buffer if buffer =~ pattern
sleep 0.25
end
raise "Failed to find pattern `#{pattern.inspect}` in session `#{@name}`"
end
end
def session(name, &block)
escaped_name = DSL.escape(name)
%x{tmux new-session -d -s #{DSL.escape(escaped_name)} -y 20}
Session.new(escaped_name).instance_eval(&block)
%x{tmux kill-session -t #{escaped_name}}
end
end
self.extend(DSL)
Object.instance_eval { include DSL::Constants }
session('ferret-test') do |name|
send_keys('vim -u NONE -N', Enter)
send_keys(':set shortmess+=A', Enter)
send_keys(":set runtimepath+=#{DSL.escape(Dir.pwd)}", Enter)
send_keys(':runtime! plugin/ferret.vim', Enter)
send_keys(Backslash, 'a', 'usr/bin/env', Backslash, Space, 'ruby', Enter)
wait_for(/module DSL/)
send_keys(':quitall!', Enter)
end