【问题标题】:Ambiguous match error in cucumber step definitions黄瓜步骤定义中的不明确匹配错误
【发布时间】:2014-05-28 11:52:16
【问题描述】:

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

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

当我运行这些功能时,这会导致黄瓜出现“模糊匹配”错误。我可以通过将 --guess 标志传递给 cucumber 来解决此错误。但我想知道为什么黄瓜在上述两个步骤定义中发现歧义,而两者显然不同。有什么方法可以在不使用 --guess 选项的情况下使其工作?

谢谢

【问题讨论】:

标签: ruby cucumber bdd


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多