当我像这样编写测试时,可行:
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
。
您将如何尝试解决此问题?我该怎么办?谢谢