2010-06-08 45 views
2

我想用一個使用Authlogic的登錄用戶編寫一些單元測試。要開始,我使用了http://github.com/binarylogic/authlogic_example託管的一些代碼。但是,我得到一個錯誤後耙測試,因爲「test_helper.rb中」及以下類的:使用Authlogic on Rails進行單元測試3

class ActionController::TestCase 
    setup :activate_authlogic 
end 

這是我的錯誤:

NameError: undefined local variable or method `activate_authlogic' for

我覺得這Authlogic例如被映射在Rails 2;也許它在Rails 3上有點不同。是否還有其他例子可以舉例說明單元測試?

非常感謝。

+1

你應該接受其中一個答案。 – fguillen 2012-09-05 21:31:18

回答

15

require 'authlogic/test_case'include Authlogic::TestCase? 我有一個類似的問題(使用RSpec的,雖然)和讀通過代碼在http://github.com/trevmex/authlogic_rails3_example

+0

在mi情況下_Rails/3.2_和_Authlogic/3.1.3_只需'需要'authlogic/test_case''需要。 – fguillen 2012-09-05 21:30:53

1

鐵軌3.1和Authlogic 3.0.3的,我有過的唯一的事情添加到啓動authlogic是

功能/支持/ env.rb

Before do 
    activate_authlogic 
end 
1

我不知道往哪裏放include Authlogic::TestCase,所以我把這個spec_helper.rb的需要和它的工作後。有一個更好的地方呢?

+1

我把它放在這樣的配置塊中:'config.include Authlogic :: TestCase' – RocketR 2012-04-19 13:56:43