本文介绍了我如何断言没有闪存变量与Cucumber-Capybara的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cucumber和Capybara运行Rails 3.0.7项目,我有一个步骤定义检查是否存在flash [:error]:

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'

这是正确的方式处理变量断言?我注意到,如果我使用会话[:something],同样类型的错误发生。

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.

推荐答案

检查页面上实际可见的内容,例如在这种情况下:

You should be checking what's actually visible on the page, e.g. in this case:

page.should_not have_css('.flash')

这篇关于我如何断言没有闪存变量与Cucumber-Capybara的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 05:55