Skip to content

Instantly share code, notes, and snippets.

@DaveSanders
Created August 6, 2010 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveSanders/511611 to your computer and use it in GitHub Desktop.
Save DaveSanders/511611 to your computer and use it in GitHub Desktop.
When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
with_scope(selector) do
fields.rows_hash.each do |name, value|
field = find_field(name)
case field[:type]
when "select-one"
When %{I select "#{value}" from "#{name}"}
when "select-multiple"
When %{I select "#{value}" from "#{name}"}
when "checkbox"
When %{I check "#{name}"} if value.downcase == "true"
When %{I uncheck "#{name}"} if value.downcase != "true"
else
When %{I fill in "#{name}" with "#{value}"}
end
end
end
end
Then /^these fields should contain the following(?: within "([^"]*)")?:$/ do |selector, fields|
with_scope(selector) do
fields.rows_hash.each do |name, value|
Then %{the "#{name}" field should equal "#{value.to_s}"}
end
end
end
Then /^the "([^"]*)" field(?: within "([^"]*)")? should equal "([^"]*)"$/ do |field, selector, value|
with_scope(selector) do
field = find_field(field)
if (field[:type] == "checkbox")
Then %{the "#{field[:id]}" checkbox should be checked} if value.downcase == "true"
Then %{the "#{field[:id]}" checkbox should not be checked} if value.downcase != "true"
else
field_value = (field.tag_name == 'textarea') ? field.text : field.value
if field_value.respond_to? :should
field_value.should == value
else
assert_match(value, field_value)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment