在Rails 5,2中,这是一个非常简单的系统测试:
require 'test_helper'
class AdminSignsInTest < ActionDispatch::SystemTestCase
driven_by :selenium, using: :firefox
test 'admin can sign in' do
@user = users(:admin)
visit new_user_session_path
fill_in 'user_username', with: @user.username
fill_in 'user_password', with: @user.encrypted_password
click_button I18n.t("devise.login")
assert_equal I18n.t('devise.failure.invalid'), flash[:alert]
end
end
返回错误:
NoMethodError: undefined method `flash' for nil:NilClass
根据Rails文档http://guides.rubyonrails.org/testing.html#testing-flash-notices,此语法应该有效,例如:
assert_equal 'Article was successfully created.', flash[:notice]
答案 0 :(得分:0)
签入@response
或response
对象必须具有警报消息。您可以尝试一下。