我想通過rspec將BDD集成到我的rails應用程序中。我正在使用警衛和spork-rails來加速監控過程。我得到這個錯誤:準備調用一個封閉的數據庫rails rspec
An error occurred in an after hook
ActiveRecord::StatementInvalid: ArgumentError: prepare called on a closed database:
rollback transaction occurred at /Users/davidhahn/.rvm/gems/ruby-1.9.3-p286/gems/sqlite3-1.3.6/lib/sqlite3/database.rb:91:in initialize
我跑rake db:test:prepare
它運行沒有任何錯誤。由於我使用的是sqlite,我檢查過以確保user_man_test.sqlite
文件位於db/
。我的測試是一個簡單的集成測試:
require 'spec_helper'
describe "Authentication" do
describe "Login Page" do
it "should have the h1 'Welcome to User Management'" do
visit '/log_in'
page.should have_selector('h1', text: 'Welcome to User Management')
end
end
describe "Login" do
before { visit '/log_in' }
describe "with invalid information" do
before { click_button "Login" }
it { should have_selector('h1', text: 'Welcome to User Management') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
end
end
end
我spec_helper.rb樣子:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
〜
感謝您的幫助
我改成了mysql,它糾正了錯誤,導致我相信它在我的sqlite3的配置中出錯了。 –