Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带有RSpec、Spork和数据库清理器的SQLite异常_Ruby On Rails_Rspec_Sqlite_Spork - Fatal编程技术网

Ruby on rails 带有RSpec、Spork和数据库清理器的SQLite异常

Ruby on rails 带有RSpec、Spork和数据库清理器的SQLite异常,ruby-on-rails,rspec,sqlite,spork,Ruby On Rails,Rspec,Sqlite,Spork,在大约5次运行中效果很好,但随后所有测试都会失败: ArgumentError: prepare called on a closed database: SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' 没有Spork不会发生,如果我重新启动Spork,效果会很好。运行一定次数后不会发生,但每次都会发生

在大约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

尝试删除此行:

config.use_transactional_fixtures = true

似乎对我有用。我被错误消息所引导,因为它与交易有关,但并不完全确定交易是什么。似乎与spork的线程和sqlite3有关尝试删除这一行:

config.use_transactional_fixtures = true

似乎对我有用。我被错误消息所引导,因为它与交易有关,但并不完全确定交易是什么。似乎与spork的线程和sqlite3有关,我经常遇到这个错误,并且能够通过更新到sqlite3的最新版本来修复它

bundle update sqlite3

我经常遇到这个错误,并且能够通过更新到sqlite3的最新版本来修复它

bundle update sqlite3