如何使用 Cucumber-Capybara 断言 flash 变量不存在?
我正在使用 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
当我运行 Cucumber 测试时,出现错误
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'
这是处理变量的正确方法吗断言?我注意到,如果我使用session[:something],会发生相同类型的错误。
I'm running a Rails 3.0.7 project with Cucumber and Capybara and I have a step definition that checks if a flash[:error] exists:
Then /^I should be able to see the main page properly$/ do
current_path.should == "/"
flash[:error].should == nil
end
When I run my cucumber test, I get an error
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'
Is this the correct way of handling variable assertions? I've noticed that if I were to use sessions[:something], the same type of error happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(任何类型的)
flash
消息集,您可以执行以下操作:要断言不存在 特定类型集(本例中为
:error
),您可以执行以下操作:To assert that there is no
flash
message set (of any type), you can do:To assert that there is no
flash
message of a particular type set (:error
in this example), you can do:您应该检查页面上实际可见的内容,例如在本例中:
You should be checking what's actually visible on the page, e.g. in this case: