I'm developing a Rails Engine (Plugin). So far I have
- Set up RSpec as a framework
- Added a migration to create a model/table called
MyJob
- Added some basic model tests under
spec/models/my_job_spec.rb
The rails template automatically creates a spec/dummy
app, so I did the following to run my test
# Create the development and test DBs
rake db:create
# Copy migrations over to my dummy app
cd spec/dummy
rake my_app:install:migrations
cd ../..
# Run specs
rspec spec/models/my_job_spec.rb
However when I run my specs, I get an error:
> rspec spec/models/
/Users/jeeves/.rvm/gems/ruby-2.2.2@gb/gems/activerecord-5.1.0/lib/active_record/migration.rb:576:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
I thought this automatically would happen because in my rails_helper.rb
I definitely have the following, which is supposed to maintain my test schema for me
ActiveRecord::Migration.maintain_test_schema!
Does it work differently with plugins or engines?
EDIT: I tried the recommendation of running bin/rails db:migrate RAILS_ENV=test
, inside spec/dummy/
and then re-running rspec spec/
. Still no luck.
ActiveRecord::Migration.maintain_test_schema!
was introduced in Rails 4.1 and still does not really work as advertised. I usually have to runrake db:test:load
after migrations to get it to properly update the test schema. – Chaparajos