LoginSignup
98
87

More than 5 years have passed since last update.

RSpecでテストデータベースの準備

Posted at
bundle exec rspec spec/

を実行すると、以下のエラーが発生する。

~vendor/bundler/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/migration.rb:379:in `check_pending!': Migrations are pending; run 'rake db:migrate RAILS_ENV=test' to resolve this issue. (ActiveRecord::PendingMigrationError)

テストデータベースが無いかららしい。
以下を実行し、テストデータベースを準備する。

bundle exec rake db:test:prepare

以前はこれだけでOKだったらしいが、Rails4だと以下も実行しないと解消されない。

bundle exec rake db:migrate RAILS_ENV=test

参考URL
Ruby on Rails Tutorial News - Preparing the test database


補足

最初に以下を実行しておけば、ハマらなかったっぽい。

bundle exec rake db:create:all

・・・読み飛ばしてた・・・orz

98
87
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
98
87