Rails5集成测试带有闪存消息的assert_equal

时间:2018-06-23 17:59:35

标签: ruby-on-rails integration-testing

在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]

1 个答案:

答案 0 :(得分:0)

签入@responseresponse对象必须具有警报消息。您可以尝试一下。