Rails 4 集成测试 - 失败(事件断言为真)

Rails 4 Integration Testing - Failing (event Assert True)

好吧,有点尴尬我昨天问了一个,但我们又卡住了。

我们已经修复了所有控制器测试,并开始编写集成测试。我们在所有集成测试中都遇到了错误,甚至是著名的 assert = true:

site_layout_test.rb

require 'test_helper'

class SiteLayoutTest < ActionDispatch::IntegrationTest


  test "the truth" do
    assert true
  end

#commenting out our real tests for debugging

=begin
  test "top navigation bar links" do
    get 'beta/index'
    assert_template 'beta/index'
    assert_select "a[href=?]", home_path
    assert_select "a[href=?]", how_it_works_path
    to do add map, community, sign up, login paths
    to do: add paths to links on dropdown if user is logged in
  end
=end

end

终端测试结果

12:31:32 - INFO - Running: test/integration/site_layout_test.rb
Started with run options --seed 27747

ERROR["test_the_truth", SiteLayoutTest, 2015-10-25 11:36:28 +0800]
 test_the_truth#SiteLayoutTest (1445744188.33s)
NoMethodError:         NoMethodError: undefined method `env' for nil:NilClass


  1/1: [===================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.05380s
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips

test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  include Devise::TestHelpers
  # Add more helper methods to be used by all tests here...
  #

  def setup_variables
    @base_title = "TripHappy"
  end
end

不幸的是,该错误消息几乎没有给我们提供关于错误发生位置的线索。我试着阅读 Minitests,但不知道去哪里看,我完全迷路了。

在此先感谢您!

作为参考,我们正在关注 M. Harti's Rails Tutorial,这意味着我们正在使用 Guard 和 Minitest Reporters。我们还有一个通过 Devise 的登录系统,如果这有什么影响的话。

解法:

这是 Devise 的问题。我在 class ActiveSupport::TestCase 中包含 include Devise::TestHelpers 而不是 class ActionController::TestCase.

这是 Devise 的问题。我在 class ActiveSupport::TestCase 中包括 Devise::TestHelpers 而不是 class ActionController::TestCase