I have defined this step:
Then /^the "([^"]*)" field(?: within (.*))? should be empty$/ do |field, parent|
with_scope(parent) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
if field_value.respond_to? :should
field_value.to_s.should == ''
else
assert_equal('', field_value.to_s)
end
end
end
and when I run my scenario it raise the following error:
Then the “City” field within the “Buying a House” form should be empty # Ambiguous match of “the “City” field within the “Buying a House” form should be empty”:
features/step_definitions/my_steps.rb:1:in `/^the "([^"]*)" field(?: within (.*))? should be empty$/'
features/step_definitions/web_steps.rb:35:in `/^(.*) within (.*[^:])$/'
The step mentioned is as following:
When /^(.*) within (.*[^:])$/ do |step, parent|
with_scope(parent) { When step }
end
So, I have a lot questions…
-
How could a possible define my step without matching that?
When /^(.*) within (.*[^:])$/seems absolutely inevitable. -
However, this step doesn’t cause ambiguity:
features/step_definitions/web_steps.rb:141
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
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
- Couldn’t I just remove the
When /^(.*) within (.*[^:])$/step? Is it part of “the system”? I mean, it IS into/step_definitions/web_steps.rb, and it comes withrake cucumber:install.
If fine to edit web_steps.rb. In fact, the latest version Cucumber suggests deleting it entirely: