适用于大约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
答案 0 :(得分:1)
尝试删除此行:
config.use_transactional_fixtures = true
似乎对我有用。我被错误消息引导,因为它与事务有关,但不完全确定交易是什么。似乎与spork的线程和sqlite3
有关答案 1 :(得分:0)
我有这个错误,并且能够通过更新到最新版本的sqlite3来修复它。
bundle update sqlite3