我对黄瓜很陌生。我正在尝试编写测试以确保用户不会创建重复的标签。于是写了一个功能,内容如下:
Scenario: Analyst adds a duplicate privacy tag
Given I have a privacy tag called "Green"
When I try to create a tag called "Green"
Then I should be on the new privacy tag page
And I should see an error message for "Green"
我的步骤是这样定义的:
Given /^I have a privacy tag called "(.*?)"$/ do |tag|
PrivacyTag.create(:content => tag)
end
When /^I try to create a tag called "(.*?)"$/ do |arg1|
visit new_privacy_tag_path
fill_in 'privacy_tag[content]', :with => arg1
click_button 'Create'
end
Then /^I should be on the new privacy tag page$/ do
new_privacy_tag_path
end
Then /^I should see an error message for "(.*?)"$/ do |arg1|
page.should have_selector('div', :class => 'alert alert-error') do |flash|
flash.should have_content fartknocker
end
end
所以奇怪的是,所有这些测试现在都通过了。当您尝试创建应用程序允许的重复隐私标签并最终进入隐私标签索引页面时,用户不会返回到 new_privacy_tag_path。但测试仍然通过。Cucumber 甚至连眼睛都不眨一下,因为在任何地方都没有定义名为 fartknocker 的变量,而且 fartknocker 这个词也没有出现在页面上的任何地方。测试仍然通过。是什么赋予了?