Ambiguous match error in cucumber step definitions

扶醉桌前 提交于 2019-12-12 01:31:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!