I'm building a Rails 5 app and I'm using Rspec for tests. I've used Travis several times in the past for Rails apps, but they were using MiniTest and Rails 4.
I can run tests locally:
joenyland@MacBook-Pro ~/Code/acrm $ rake db:drop
Dropped database 'db/development.sqlite3'
Database 'db/test.sqlite3' does not exist
joenyland@MacBook-Pro ~/Code/acrm $ RAILS_ENV=test bundle exec rake
/Users/joenyland/.rvm/rubies/ruby-2.3.0/bin/ruby -I/Users/joenyland/.rvm/gems/ruby-2.3.0@acrm/gems/rspec-core-3.5.4/lib:/Users/joenyland/.rvm/gems/ruby-2.3.0@acrm/gems/rspec-support-3.5.0/lib /Users/joenyland/.rvm/gems/ruby-2.3.0@acrm/gems/rspec-core-3.5.4/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
*.............................
Pending: (Failures listed here are expected and do not affect your suite's status)
1) SessionsHelper add some examples to (or delete) /Users/joenyland/Code/acrm/spec/helpers/sessions_helper_spec.rb
# Not yet implemented
# ./spec/helpers/sessions_helper_spec.rb:14
Finished in 1.87 seconds (files took 15.63 seconds to load)
30 examples, 0 failures, 1 pending
But when Travis runs the tests, it fails:
0K$ bundle exec rake
/home/travis/.rvm/rubies/ruby-2.3.0/bin/ruby -I/home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib:/home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-support-3.5.0/lib /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
/home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:572:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:585:in `load_schema_if_pending!'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:591:in `block in maintain_test_schema!'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:822:in `suppress_messages'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:596:in `method_missing'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:591:in `maintain_test_schema!'
from /home/travis/build/MasterRoot24/acrm/spec/rails_helper.rb:27:in `<top (required)>'
from /home/travis/build/MasterRoot24/acrm/spec/models/client_spec.rb:1:in `require'
from /home/travis/build/MasterRoot24/acrm/spec/models/client_spec.rb:1:in `<top (required)>'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `load'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
from /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/exe/rspec:4:in `<main>'
/home/travis/.rvm/rubies/ruby-2.3.0/bin/ruby -I/home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib:/home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-support-3.5.0/lib /home/travis/build/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
My Travis config:
language: ruby
cache: bundler
I know the obvious solution is to add a before script to the Travis config to run rails db:migrate RAILS_ENV=test
. However, my question is why is this suddenly required when I've never needed to do it before?
Has something changed in the Rspec implementation for Rails 5 that means migrations aren't run before tests automatically now? (I assume this is what used to happen...)
I should add that spec/rails_helper.rb
contains the lines:
# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
...so it looks like it should be running the migrations.
UPDATE 3/11/2016
With a little help from Travis, I've managed to recreate this issue outside of Travis' infrastructure.
Travis runs builds on their container based infrastructure and their image (quay.io/travisci/travis-ruby
) is based on Ubuntu 12.04.5 (Precise).
I can now recreate the issue like so:
docker run -it ubuntu:precise /bin/bash
apt-get update && apt-get install git bash-completion curl nodejs -y && gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 && \curl -sSL https://get.rvm.io | bash -s stable && source /etc/profile.d/rvm.sh && rvm install 2.3.0 && git clone --depth=50 --branch=master https://github.com/MasterRoot24/acrm.git MasterRoot24/acrm && cd MasterRoot24/acrm && rvm use 2.3.0 && gem install bundler && export BUNDLE_GEMFILE=$PWD/Gemfile && bundle install --jobs=3 --retry=3 --deployment --path=${BUNDLE_PATH:-vendor/bundle} && bundle exec rake
root@e4f741e8c189:/MasterRoot24/acrm# bundle exec rake
/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby -I/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/lib:/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-support-3.5.0/lib /MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
/MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:572:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
from /MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:585:in `load_schema_if_pending!'
from /MasterRoot24/acrm/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/migration.rb:591:in `block in maintain_test_schema!'
If I do the same locally on macOS 10.12 or in Debian Jessie, tests pass and I am not asked to run a manual migration.
Why would I need to run a manual migration under Ubuntu 12.04, but not under any other OS?