Rails 5测试NoMethodError

时间:2016-02-19 03:14:52

标签: ruby-on-rails ruby testing ruby-on-rails-5

我正在将现有应用程序从Rails 4升级到5.0.0.beta2。它实际上运行得很漂亮!

但是,我遇到了控制器测试的问题。它抛出了这个错误:

    E

    Error:
    SeiteControllerTest#test_should_get_index:
    NoMethodError: undefined method `each' for nil:NilClass

    bin/rails test test/controllers/seite_controller_test.rb:14

    Finished in 1.068562s, 0.9358 runs/s, 0.0000 assertions/s.

    1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

以下是代码(使用标准test_helper):

    require 'test_helper'

    class SeiteControllerTest < ActionController::TestCase

      setup do 

      end

      test "should get index" do
        #get :index
      end

    end

第14行是&#34;测试应该得到索引&#34;线。毋庸置疑,如果我取消评论&#34; get:index&#34;我知道同样的错误。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。为我修复的是将以下内容放在test_helper.rb

的末尾
class ActionDispatch::IntegrationTest
  include Rails::Controller::Testing::TestProcess
  include Rails::Controller::Testing::TemplateAssertions
  include Rails::Controller::Testing::Integration
end