2010-02-16 31 views
0

我有一些代碼增加了rspec-rails默認添加到setup and teardown fixtures的回調。如何添加到rspec-rails回調

我的代碼看起來是這樣的:

module Test 
    module Unit 

    class TestCase 
     append_before(:each) do 
     Test::Unit::AfterFixturesLoaded.custom_stuff1 
     end 

     append_after(:each) do 
     Test::Unit::AfterFixturesLoaded.custom_stuff2 
     end 
    end 

    class AfterFixturesLoaded 

     def self.custom_stuff1 
     #do some stuff here 
     end 

     def self.custom_stuff2 
     #do some other stuff here 
     end 
    end 

    end 
end 

此代碼工作正常,如果我把它在Rails應用程序中的config \ initializers目錄,但隨後運行的應用程序失敗,因爲它不會加載試驗裝置。所以我的問題是我可以在哪裏放置這些代碼,以便在運行rspec時始終包含它?

回答

0

因爲你只打算使用此代碼進行測試,因此是有意義的把它放在一個單獨的文件,然後要求其在environments/test.rb例如require 'filename.rb'