I want to run tests using rspec on my ruby on rails app using sqlite with the memory database. However, everytime I launch rspec it tells me that migrations are pending, event if I run the migrations before hand. Is there a way to do the migrations everytime before I run the tests ? Here's my database configuration
test:
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
database: ":memory:"
You need to load schema in your tests instead of relying on migrations.
As advised in this blogpost replace
ActiveRecord::Migration.maintain_test_schema!
with
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.verbose = false
load "#{Rails.root.to_s}/db/schema.rb"