黄瓜步骤定义中的模糊匹配错误 [英] 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
当我运行这些功能时,会导致cucumber的Ambiguous Match错误。我可以通过传递 - guess 标志到黄瓜解决这个错误。但我想知道为什么黄瓜在上述两个步骤定义中发现歧义,当两者明显不同时。有没有办法让它工作,而不使用--guess选项?
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 ?
谢谢
推荐答案
第一步匹配第二步执行的所有操作。即使使用非贪婪修饰符,。*?
匹配bar中的foo。修正它像这样:
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
这篇关于黄瓜步骤定义中的模糊匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!