1

我有一个 Rails 4 应用程序,我正在尝试使用内存中的 sqlite 数据库在 rspec 中进行测试。当我跑步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 内存数据库进行测试的正确方法是什么?

更新

运行时rake -trake 似乎正在尝试运行迁移

** 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

我不需要运行迁移。是否可以覆盖这种看似默认的行为。

4

0 回答 0