2010-04-22 41 views
1

當我運行「耙測試」不加載裝置?

rake test --trace 

這裏的

** Invoke test (first_time) 
** Execute test 
** Invoke test:units (first_time) 
** Invoke db:test:prepare (first_time) 
** Invoke db:abort_if_pending_migrations (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Execute db:abort_if_pending_migrations 
** Execute db:test:prepare 
** Invoke db:test:load (first_time) 
** Invoke db:test:purge (first_time) 
** Invoke environment 
** Execute db:test:purge 
** Execute db:test:load 
** Invoke db:schema:load (first_time) 
** Invoke environment 
** Execute db:schema:load 
** Execute test:units 
/usr/bin/ruby1.8 -I"lib:test".... (and after that fails because there's no fixtures loaded) 

,爲什麼不把它加載夾具會發生什麼(我認爲這將是默認行爲),我如何讓它執行測試前加載燈具? ??

p.s.

我的測試/ test_helper.rb中內容是:

ENV["RAILS_ENV"] = "test" 
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") 
require 'test_help' 

class ActiveSupport::TestCase 
self.use_transactional_fixtures = true 
self.use_instantiated_fixtures = false 
fixtures :all 
end 

(軌2.3.4)

+0

對於它的價值,我遇到了類似的問題,除了我定義了一個依賴於數據庫記錄的常量。將該常量移至實例變量和booya。乾杯。 – 2011-03-01 19:34:24

回答

4

rake test負載燈具如果指定fixtures :all像你一樣。 夾具有問題嗎?

嘗試rake db:fixtures:load並檢查是否有錯誤發生。

此外,我強烈建議跳過裝置而傾向於工廠。

+0

謝謝你的回答 - 我只是意識到一切正常執行。我的問題是模型代碼在加載Fixtures之前被檢查,並且我的一些模型驗證依賴於現有記錄(如validates_attachment_size:body,:less_than => AdminOptions.first.max_file_size.megabytes)。 – 2010-04-22 13:39:06

+0

它是「rake db:fixtures:load」,而不是「rake fixture:load」 – Rob 2014-10-14 18:43:47

+2

這是「RAILS_ENV =測試rake db:fixtures:load」,而不是「rake fixtures:load」 – Rob 2014-10-14 18:52:45