Extract user acceptance test helpers in a module

This commit is contained in:
Thibault Jouan
2015-04-13 01:56:08 +00:00
parent 10591d0646
commit 53d83d5f08
10 changed files with 84 additions and 59 deletions

View File

@@ -1,20 +1,3 @@
def uhwm_wait_output message, timeout: 1
Timeout.timeout(timeout) do
loop do
break if case message
when Regexp then @process.stdout + @process.stderr =~ message
when String then assert_partial_output_interactive message
end
sleep 0.1
end
end
rescue Timeout::Error
fail [
"expected `#{message}' not seen after #{timeout} seconds in:",
" ```\n #{@process.stdout + @process.stderr} ```"
].join "\n"
end
Then /^the output must contain exactly the usage$/ do
assert_exact_output <<-eoh, all_output
Usage: uhwm [options]
@@ -29,17 +12,13 @@ options:
end
Then /^the output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options|
expect(@process.stdout).to match Regexp.new(pattern, options)
end
Then /^the current output must match \/([^\/]+)\/([a-z]*)$/ do |pattern, options|
uhwm_wait_output Regexp.new(pattern, options)
end
Then /^the current output must contain:$/ do |content|
Then /^the output must contain:$/ do |content|
uhwm_wait_output content.to_s
end
Then /^the current output must contain current display$/ do
Then /^the output must contain current display$/ do
uhwm_wait_output ENV['DISPLAY']
end

View File

@@ -1,16 +1,5 @@
def uhwm_run options = '-v'
command = %w[uhwm]
command << options if options
@interactive = @process = run command.join ' '
end
def uhwm_run_wait_ready
uhwm_run
uhwm_wait_output 'Connected to'
end
Given /^another window manager is running$/ do
expect(@other_wm).to be_alive
expect(other_wm).to be_alive
end
Given /^uhwm is running$/ do

View File

@@ -1,21 +1,8 @@
def x_key key
fail "cannot simulate X key `#{key}'" unless system "xdotool key #{key}"
end
def x_socket_check pid
case RbConfig::CONFIG['host_os']
when /linux/
`netstat -xp 2> /dev/null`.lines.grep /\s+#{pid}\/ruby/
else
`sockstat -u`.lines.grep /\s+ruby.+\s+#{pid}/
end.any?
end
When /^I press the default quit key binding$/ do
x_key 'alt+q'
end
Then /^it must connect to X display$/ do
uhwm_wait_output 'Connected to'
expect(x_socket_check @process.pid).to be true
expect(x_socket_check uhwm_pid).to be true
end