2010-12-08 25 views
0

我對新建立的rails項目存在以下問題。不知何故,我似乎無法正確使用Devise helpers(例如sign_in)。設計測試幫手不加載,或在RSpec中正確要求

在我的規格/支持目錄。我有一個文件名爲設計出要按照設備的自述文件,包括輔助方法,因此您可以在RSpec中使用它們:

RSpec.configure do |config| 
    config.include Devise::TestHelpers, :type => :controller 
end 

我spec_helper.rb有,當然:

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 

我一直在爭取這件事一個多小時,這讓我瘋狂。非常感謝幫助!

使用:

  1. Rspec的2.2.0
  2. 設計1.1.5
  3. 的Rails 3.0.3
+0

>>我有一個名爲devise的文件<<你的意思是`devise.rb`,對嗎? – zetetic 2010-12-08 19:22:30

回答

0

雖然現在看來,這應該是相同的,我建議嘗試在你的rspec測試中明確包含testhelpers。就像這樣:

require 'spec_helper' 

describe DoStuffController do 
    include Devise::TestHelpers 

    before (:each) do 
    @user = Factory.create(:user) 
    sign_in @user 
    end 

    ... do your stuff ... 

end 

如果還是失敗,我以爲會,我希望你至少會獲得更好的錯誤。

+0

完全一樣的錯誤。在我的其他項目中,運行相同版本的rspec和devise,它似乎仍然工作正常。 – 2010-12-08 11:51:05