我正在使用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')