如何使用Cucumber-Capybara断言是否存在闪存变量?
我正在使用Cucumber和Capybara运行Rails 3.0.7项目,我有一个步骤定义,检查是否存在flash [:error]:
Then /^I should be able to see the main page properly$/ do current_path.should == "/" flash[:error].should == nil end
当我进行黄瓜测试时,我收到错误
And I should be able to see the main page properly # features/step_definitions/user_auth_steps.rb:17 undefined method `flash' for nil:NilClass (NoMethodError) ./features/step_definitions/user_auth_steps.rb:19:in `/^I should be able to see the main page properly$/' features/user_auth.feature:10:in `And I should be able to see the main page properly'
这是处理变量断言的正确方法吗? 我注意到如果我使用会话[:某事],就会发生同样的错误。
您应该检查页面上实际可见的内容,例如在这种情况下:
page.should_not have_css('.flash')
要声明没有 flash
消息集(任何类型),您可以执行以下操作:
assert_predicate flash, :empty?
要声明没有特定类型集的flash
消息(在此示例中为:error
),您可以执行以下操作:
assert_predicate flash[:error], :nil?