1

适用于大约 5 次运行,但随后所有测试都失败了:

ArgumentError: prepare called on a closed database:           SELECT name
             FROM sqlite_master
             WHERE type = 'table' AND NOT name = 'sqlite_sequence'

没有 Spork 就不会发生,如果我重新启动 Spork 就可以正常工作。运行一定次数后不会发生,但每次都会改变。

有什么想法可能导致这种情况吗?

编辑:

它仅在更改控制器代码时发生。

spec_helper.rb:

require 'spork'
require 'simplecov'
SimpleCov.start

Spork.prefork do
  ENV['RAILS_ENV'] ||= 'test'

  require File.expand_path('../../config/environment', __FILE__)
  require 'rspec/rails'
end

Spork.each_run do # This code will be run each time you run your specs.
  require 'capybara/rspec'
  require 'capybara/rails'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}

  RSpec.configure do |config|
    config.mock_with :rspec

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false

    config.include RequestHelpers, :type => :request

    config.before :suite do
      DatabaseCleaner.strategy = :truncation
      DatabaseCleaner.clean_with :truncation
    end

    config.before :each do
      DatabaseCleaner.start
    end

    config.after :each do
      DatabaseCleaner.clean
    end

    config.include(MailerHelpers)
    config.before(:each) { reset_email }
  end
end
4

2 回答 2

1

尝试删除此行:

config.use_transactional_fixtures = true

似乎对我有用。我被错误消息引导,因为它与交易相关,但不完全确定交易是什么。似乎与 spork 的线程和 sqlite3 有关

于 2013-03-08T21:20:10.600 回答
0

我有很多这个错误,并且能够通过更新到最新版本的 sqlite3 来修复它。

bundle update sqlite3
于 2016-11-11T18:10:01.320 回答