问题
In my cucumber step definitions I have the following
Then /^I should see "(.*?)"$/ do |text|
page.should have_content(text)
end
Then /^I should see "(.*?)" within "(.*?)"$/ do |text,css|
within(css) do
page.should have_content(text)
end
end
This causes an "Ambiguous Match" error by cucumber when I run the features. I can work around this error by passing the --guess flag to cucumber. But I'm wondering why cucumber is finding ambiguity in the above two step definitions when both are clearly different. Is there any way to make it work without using the --guess option ?
Thanks
回答1:
The first step matches everything the second step does. Even with the non-greedy modifier, ".*?"
matches "foo" within "bar"
. Fix it like this:
Then /^I should see "([^"]*)"$/ do |text|
page.should have_content(text)
end
来源:https://stackoverflow.com/questions/23910899/ambiguous-match-error-in-cucumber-step-definitions