加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何使用Cucumber-Capybara断言是否存在闪存变

发布时间:2020-12-17 07:08:36 所属栏目:百科 来源:网络整理
导读:我正在使用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 == nilend 当我进行黄瓜测试时,我收到一
我正在使用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')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读