2015-10-04 81 views
0

我正在使用SQLite的Rails 4.2.3。我有一個簡單的'assert'單元測試,使用內置的ActiveSupport :: TestCase。Rails 4生成測試數據庫

db/migrate中有一個遷移。

我不知道爲什麼下列原因的測試運行成功,我希望能得到一個「待定遷移」的錯誤:

rwc $ rake db:drop:all 
rwc $ rake db:migrate:status 
Schema migrations table does not exist yet. 
rwc $ rake db:migrate:status RAILS_ENV=test 
Schema migrations table does not exist yet. 
rwc $ rake test 
Run options: --seed 43484 

# Running: 

. 

Finished in 0.011646s, 85.8671 runs/s, 85.8671 assertions/s. 

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips 

測試不與數據庫交互,我仍然希望那裏是由於未應用遷移而導致的錯誤。

任何人都可以解釋這種行爲嗎?

回答

0

真的只是閱讀以下內容:

In order to run your tests, your test database will need to have the current structure. The test helper checks whether your test database has any pending migrations. If so, it will try to load your db/schema.rb or db/structure.sql into the test database. If migrations are still pending, an error will be raised. Usually this indicates that your schema is not fully migrated. Running the migrations against the development database (bin/rake db:migrate) will bring the schema up to date.

參考:http://guides.rubyonrails.org/testing.html#rails-sets-up-for-testing-from-the-word-go