Rails 5.1语法在系统测试中测试flash消息

时间:2017-05-19 20:37:58

标签: ruby-on-rails

您是否知道使用系统测试测试Flash消息的语法?

这就是我目前正在撰写的内容......

test 'New User signup' do
  # ...
  click_button 'Create User'
  assert_equal 'User was successfully created.', flash[:notice]
end

失败的测试屏幕截图显示闪存存在,但测试失败并带有

NoMethodError: NoMethodError: undefined method `flash' for nil:NilClass

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我最终改变了断言:

assert_equal 'User was successfully created.', flash[:notice]

为:

assert_selector "#notice", text: 'User was successfully created.'

似乎可以解决问题。