19

So according to this link one is a shortcut wrapper (so I'm guessing they're the same).

When I ran bundle exec rake db:test:prepare, I get this error:

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 `<main>'

...but when I ran bundle exec rake db:test:prepare , I get this warning:

WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.

Can anyone shed light on this?

Community
  • 1
  • 1
ayjay
  • 1,272
  • 2
  • 16
  • 25
  • I think the error should instead suggest the syntax @Logan Serman mentioned. It's presumptuous to assume anyone's test/spec helper would have the "updated" syntax. – Tass Feb 11 '15 at 14:24

1 Answers1

50

In Rails 4.1+, they deprecated db:test:prepare with that message. You can now just use:

ActiveRecord::Migration.maintain_test_schema!

in spec_helper.rb (or similar files if you're not using RSpec). That will automatically keep your test database in sync with your schema. Because of this 'automatic' method, db:test:prepare is no longer needed in most cases.

If you need to do it manually for some reason, you can still use

rake db:schema:load RAILS_ENV=test

Logan Serman
  • 29,447
  • 27
  • 102
  • 141
  • Spring definitely has some issues, but I've been using Rails 4.1 every day since beta and never had a problem using `maintain_test_schema!` and Spring. – Logan Serman Oct 23 '14 at 11:48
  • 6
    A potential gotcha `ActiveRecord::Migration.maintain_test_schema!` fails to work correctly when a migration is added, tests are run, then `rake db:rollback` is used, then the migration is changed. It then thinks the schema is up to date when it's not. – JamieD Dec 16 '14 at 14:55
  • Running Rails 4.1.0, couldn't get it to work -- had an `UninitializedConstant` error for ActiveRecord. Not sure what happened. – Erik Trautman Mar 28 '15 at 19:17
  • Here's a nice [documentation](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade) from RSpec. – konyak Jul 22 '15 at 15:10
  • @JamieD is this a noted bug in the ActiveRecord repo? – nobody Nov 23 '15 at 18:00