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

时间:2015-10-28 04:37:37

标签: ruby-on-rails ruby-on-rails-4 testing integration-testing minitest

好吧,昨天我问very similar question有点尴尬,但我们又被卡住了。

我们修复了所有控制器测试,并开始编写集成测试。我们在所有集成测试中遇到错误,甚至是着名的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的一个问题。我在include Devise::TestHelpers而不是class ActiveSupport::TestCase中添加了class ActionController::TestCase

1 个答案:

答案 0 :(得分:0)

这是Devise的一个问题。我在ActiveSupport :: TestCase类中包含了Devise :: TestHelpers而不是ActionController :: TestCase类