简体   繁体   English

黄瓜步骤定义中的歧义匹配错误

[英]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. 我可以通过将--guess标志传递给黄瓜来解决此错误。 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 ? 有没有办法使它不使用--guess选项就可以工作?

Thanks 谢谢

The first step matches everything the second step does. 第一步与第二步的所有操作匹配。 Even with the non-greedy modifier, ".*?" 即使使用非贪婪修饰符, ".*?" matches "foo" within "bar" . 匹配"foo" within "bar"中的"foo" within "bar" Fix it like this: 像这样修复它:

Then /^I should see "([^"]*)"$/ do |text|
   page.should have_content(text)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM