chriskottom / minitest_cookbook_source

Source code examples and sample projects for The Minitest Cookbook
54 stars 20 forks source link

ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: commit transaction #3

Open JunichiIto opened 9 years ago

JunichiIto commented 9 years ago

minishop test fails like this:

➜  minishop git:(master) bundle exec rake test
Run options: --seed 58825

# Running:

.................E......................................

Fabulous run in 9.343703s, 5.9933 runs/s, 20.6556 assertions/s.

  1) Error:
Shopping Feature Test#test_0001_add several items to the cart and check out:
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: commit transaction
    app/controllers/line_items_controller.rb:12:in `block in create'
    app/controllers/line_items_controller.rb:11:in `create'

56 runs, 193 assertions, 0 failures, 1 errors, 0 skips

So I changed test_helper.rb like this:

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/rails'
require 'minitest/pride'

require 'minitest/rails/capybara'
Capybara.default_wait_time = 1

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

# Capybara.javascript_driver = :webkit

require "support/session_helpers"
require "support/shopping_helpers"

class ActiveSupport::TestCase
  include SessionHelpers

  fixtures :all
end

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil
  def self.connection
    @@shared_connection || retrieve_connection
  end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

I think it is worth mentioning in the book.

chriskottom commented 9 years ago

I'm of two minds on this question. While I think I don't want to divert attention away from the main point of this chapter which is about writing the actual tests, I can see where this issue might cause problems for readers, even though it's pretty common and well-documented.

I'll make a note of it in the next update since I think it will save others some time. Thanks for pointing it out!

JunichiIto commented 9 years ago

I'll make a note of it in the next update since I think it will save others some time.

Great, thank you!