Simplify cucumber X steps

This commit is contained in:
Thibault Jouan 2015-04-21 07:24:03 +00:00
parent c7bd6ea28a
commit 6346eb5ee6
3 changed files with 35 additions and 53 deletions

View File

@ -9,7 +9,7 @@ Feature: layout protocol
end end
def << client def << client
puts client puts "testing_#{client.name}"
end end
end end
""" """
@ -21,4 +21,4 @@ Feature: layout protocol
Scenario: tells the layout to manage a client with #<< message Scenario: tells the layout to manage a client with #<< message
Given uhwm is running with options -v -r./layout -l Layout Given uhwm is running with options -v -r./layout -l Layout
When a window requests to be mapped When a window requests to be mapped
Then the output must contain the window name Then the output must contain "testing_XClient/default"

View File

@ -1,10 +1,10 @@
Given /^a (\w+) window is mapped$/ do |ident| Given /^a (\w+) window is mapped$/ do |ident|
x_window_map ident: ident x_client(ident).map.sync
end end
Given /^a window is managed$/ do Given /^a window is managed$/ do
x_window_map x_client.map.sync
uhwm_wait_output /manag.+#{x_window_name}/i uhwm_wait_output /manag.+#{x_client.name}/i
end end
When /^I press the ([^ ]+) keys?$/ do |keys| When /^I press the ([^ ]+) keys?$/ do |keys|
@ -12,41 +12,41 @@ When /^I press the ([^ ]+) keys?$/ do |keys|
end end
When /^a window requests to be mapped$/ do When /^a window requests to be mapped$/ do
x_window_map x_client.map.sync
end
When /^the window requests to be unmapped$/ do
x_window_unmap
end
When /^the (\w+) window is unmapped$/ do |ident|
x_window_unmap ident: ident
uhwm_wait_output /unmanag.+#{x_client(ident: ident).name}/i
end end
When /^a window requests to be mapped (\d+) times$/ do |times| When /^a window requests to be mapped (\d+) times$/ do |times|
x_window_map times: times.to_i x_client.map times: times.to_i
end
When /^the window requests to be unmapped$/ do
x_client.unmap.sync
end
When /^the (\w+) window is unmapped$/ do |ident|
x_client(ident).unmap.sync
uhwm_wait_output /unmanag.+#{x_client(ident).name}/i
end end
When /^the window is destroyed$/ do When /^the window is destroyed$/ do
x_window_destroy x_client.destroy.sync
end end
Then /^it must connect to X display$/ do Then /^it must connect to X display$/ do
uhwm_wait_output 'Connected to' uhwm_wait_ready
expect(x_socket_check uhwm.pid).to be true expect(x_socket_check uhwm.pid).to be true
end end
Then /^the window must be mapped$/ do Then /^the window must be mapped$/ do
expect(x_window_map_state).to eq 'IsViewable' expect(x_window_map_state x_client.window_id).to eq 'IsViewable'
end end
Then /^the (\w+) window must be mapped$/ do |ident| Then /^the (\w+) window must be mapped$/ do |ident|
expect(x_window_map_state ident: ident).to eq 'IsViewable' expect(x_window_map_state x_client(ident).window_id).to eq 'IsViewable'
end end
Then /^the window must be focused$/ do Then /^the window must be focused$/ do
expect(x_focused_window_id).to eq x_window_id expect(x_focused_window_id).to eq x_client.window_id
end end
Then /^the input event mask must include (.+)$/ do |mask| Then /^the input event mask must include (.+)$/ do |mask|

View File

@ -44,9 +44,13 @@ module Uh
].join "\n" ].join "\n"
end end
def uhwm_wait_ready
uhwm_wait_output LOG_CONNECTED
end
def uhwm_run_wait_ready options = nil def uhwm_run_wait_ready options = nil
if options then uhwm_run options else uhwm_run end if options then uhwm_run options else uhwm_run end
uhwm_wait_output LOG_CONNECTED uhwm_wait_ready
end end
def with_other_wm def with_other_wm
@ -60,11 +64,15 @@ module Uh
@other_wm @other_wm
end end
def x_client ident: :default def x_client ident = :default
@x_clients ||= {} @x_clients ||= {}
@x_clients[ident] ||= XClient.new(ident) @x_clients[ident] ||= XClient.new(ident)
end end
def x_clients_ensure_stop
@x_clients and @x_clients.any? and @x_clients.values.each &:terminate
end
def x_focused_window_id def x_focused_window_id
Integer(`xdpyinfo`[/^focus:\s+window\s+(0x\h+)/, 1]) Integer(`xdpyinfo`[/^focus:\s+window\s+(0x\h+)/, 1])
end end
@ -88,35 +96,8 @@ module Uh
end.any? end.any?
end end
def x_window_id **options def x_window_map_state window_id
x_client(options).window_id `xwininfo -id #{window_id}`[/Map State: (\w+)/, 1]
end
def x_window_name
x_client.window_name
end
def x_window_map times: 1, **options
times.times { x_client(options).map }
x_client(options).sync
end
def x_window_map_state **options
`xwininfo -id #{x_window_id options}`[/Map State: (\w+)/, 1]
end
def x_window_unmap **options
x_client(options).unmap
x_client(options).sync
end
def x_window_destroy **options
x_client(options).destroy
x_client(options).sync
end
def x_clients_ensure_stop
@x_clients and @x_clients.any? and @x_clients.values.each &:terminate
end end
@ -177,7 +158,8 @@ module Uh
@name @name
end end
def map def map times: 1
times.times { window.map }
window.map window.map
self self
end end