Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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