インメモリ sqlite データベースを使用して rspec でテストしようとしている Rails 4 アプリケーションがあります。私が実行するrake
と、それは教えてくれます
You have 66 pending migrations. Run `rake db:migrate` to update your database then try again.
spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
require 'rspec/autorun'
require 'capybara/poltergeist'
require 'faker'
require 'rake'
load_schema = lambda {
load "#{Rails.root.to_s}/db/schema.rb"
}
load_schema[]
...
このエラーが発生するのはなぜですか? スキーマ ファイルをロードするだけなのに、なぜ移行を実行する必要があるのですか? sqlite インメモリ db を使用してテストする正しい方法は何ですか?
アップデート
実行時rake -t
rake が移行を実行しようとしているようです
** Invoke default (first_time)
** Invoke spec (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:test:purge
** Execute db:test:load
** Invoke db:test:load_schema (first_time)
** Invoke db:test:purge
** Execute db:test:load_schema
** Invoke db:schema:load (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:load
** Invoke db:test:load
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment
** Execute db:abort_if_pending_migrations
移行を実行する必要はありません。この一見デフォルトの動作をオーバーライドすることは可能ですか?