Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Created March 30, 2011 17:04
Show Gist options
  • Save bjeanes/894811 to your computer and use it in GitHub Desktop.
Save bjeanes/894811 to your computer and use it in GitHub Desktop.
steps.rb
When /^I eval: (.*)$/ do |ruby|
p eval(ruby)
end
When /^I wait for (\d+) (second|minute)s?$/ do |count, period|
sleep count.to_i.send(period)
end
When /^I pause$/ do
print "Press [Enter] to continue"
$stdin.gets
end
When /^I go interactive$/ do
require 'readline'
puts "^D to exit the console, '.list' to show current steps, '.dump' to copy steps to clipboard, '.clear' to clear steps"
valid_steps = []
while line = Readline.readline('>> ', true)
line.strip!
begin
if line =~ /^(Given|When|Then|And|But).*?(:)?$/
if $2
while l = Readline.readline("#{$1} >> ")
line += "\n #{l}"
end
end
steps line
valid_steps << line
elsif line == '.dump'
IO.popen('pbcopy', 'w') do |f|
f.puts valid_steps.join("\n")
end
puts "Copied #{valid_steps.length} steps to clipboard."
valid_steps.clear
elsif line == '.list'
puts valid_steps.join("\n")
elsif line == '.clear'
valid_steps.clear
else
puts "=> #{eval(line, binding).inspect}"
end
rescue => e
p e
end
end
end
Then /^I should see the following availability:$/ do |table|
actual_availability = all("table.bookings td.day").inject({}) do |hash, cell|
hash.tap do |hash|
within(:xpath, cell.path) do
date = find("time")["datetime"]
available = find("details").text.strip
hash[date] = available
end
end
end
table.hashes.each do |date, available|
actual_availability[date].should == available
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment