user3683464
user3683464

Reputation: 3

Ambiguous match error in cucumber step definitions

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

Upvotes: 0

Views: 2564

Answers (1)

Dave Schweisguth
Dave Schweisguth

Reputation: 37657

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

Upvotes: 0

Related Questions