启动使用SQLite RSpec的测试:内存: - “迁移正在等待”

问题描述 投票:0回答:1

我想在使用SQLite与内存数据库的Rails应用程序在我的红宝石运行使用RSpec的测试。然而,每次我启动rspec的它告诉我,迁移未决,事件,如果我的手之前运行迁移。有没有一种方法之前,我进行的测试,做好迁移每次?这里是我的数据库配置

test:
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  database: ":memory:"
ruby-on-rails sqlite rspec-rails
1个回答
0
投票

您需要在您的测试加载架构而不是依靠迁移。

作为this blogpost建议更换

ActiveRecord::Migration.maintain_test_schema!

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.verbose = false
load "#{Rails.root.to_s}/db/schema.rb"
© www.soinside.com 2019 - 2024. All rights reserved.