设计控制器测试未定义的方法`env'为零:NilClass

时间:2016-11-12 22:32:37

标签: ruby-on-rails devise

当我像这样编写测试时,可行

require 'test_helper'

class HomeControllerTest < ActionController::TestCase
  include Devise::Test::ControllerHelpers

  test "signed in" do
      sign_in users(:default)
      get :show, params: { id: 33 }
      assert_redirected_to user_session_path
  end
end

然而,当我使用describe更改我的测试类的样式时:

require 'test_helper'

describe HomeController do
  include Devise::Test::ControllerHelpers

  describe "signed in" do
    it "works" do
      sign_in users(:default)
      get :show, params: { id: 33 }
      assert_redirected_to user_session_path
    end
  end
end

然后我收到以下错误:

undefined method `env' for nil:NilClass

我想这是因为Devise::Test::ControllerHelpers因为describe HomeController不再是ActionController::TestCase

您将如何尝试解决此问题?我该怎么办?谢谢

0 个答案:

没有答案