在我的一些控制器的使用設計的CURRENT_USER我需要使用屬於我的登錄用戶(current_user.groups
)的組(S)。當我嘗試測試時;我似乎沒有這個current_user
雖然:在試驗單位
ActionView::Template::Error: undefined method `authenticate' for nil:NilClass
所以我想我應該創建設計出CURRENT_USER。
我讀過制定的,說明我應該添加以下到我的test_helper.rb中文檔:
class ActionController::TestCase
include Devise::TestHelpers
def setup
@request.env["devise.mapping"] = Devise.mappings[:user]
sign_in FactoryGirl.create(:user)
end
end
這似乎並不雖然做的伎倆;每當我跑rake test
我得到以下錯誤:
1) Error:
ActivitiesControllerTest#test_should_create_activity:
NameError: uninitialized constant ActionController::TestCase::FactoryGirl
test/test_helper.rb:22:in `setup'
你已包括在你的Gemfile的測試組中的factory_girl_rails寶石? – Richard
我是假設它來與設計的寶石。由於整個登錄/註冊事情在我的應用程序中像一個魅力。 – CaptainCarl
比爲什麼不我需要它正常登錄? – CaptainCarl