Ruby 步骤定义中存在不明确的匹配错误

Ruby 步骤定义中存在不明确的匹配错误,ruby,cucumber,bdd,Ruby,Cucumber,Bdd,在我的cucumber步骤定义中,我有以下内容 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 这会导致cucumber在运行特性时出现“

在我的cucumber步骤定义中,我有以下内容

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
这会导致cucumber在运行特性时出现“不明确匹配”错误。我可以通过将--guess标志传递给cucumber来解决此错误。但我想知道为什么cucumber在上述两个步骤的定义中发现了歧义,而这两个步骤显然是不同的。有没有办法不使用--guess选项就能让它工作


谢谢

第一步符合第二步所做的一切。即使使用非贪婪修饰符,
“*?”
也会匹配“bar”中的
“foo”。像这样修复它:

Then /^I should see "([^"]*)"$/ do |text|
   page.should have_content(text)
end
类似但不完全相同