当我运行`bundle exec rake test:prepare`它出错了,但是`bundle exec rake db:test:prepare`会很好地发出警告。 这是怎么回事?
所以根据这个链接,一个是快捷包装器(所以我猜它们是相同的)。
当我运行bundle exec rake db:test:prepare
,我收到此错误:
Don't know how to build task 'test:prepare' /Users/aj/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval' /Users/aj/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `'
…但是当我运行bundle exec rake db:test:prepare
,我收到此警告:
WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.
任何人都可以阐明这一点吗?
在Rails 4.1+中,他们弃用db:test:使用该消息进行准备。 您现在可以使用:
ActiveRecord::Migration.maintain_test_schema!
在spec_helper.rb中(如果您没有使用RSpec,则为类似文件)。 这将自动使您的测试数据库与您的架构保持同步。 由于这种“自动”方法,在大多数情况下不再需要db:test:prepare。
如果由于某种原因需要手动完成,您仍然可以使用
rake db:schema:load RAILS_ENV=test