2015-10-04 104 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