3

我正在尝试通过 rspec 将 BDD 集成到我的 rails 应用程序中。我正在使用防护和 spork-rails 来加快监控过程。我收到此错误:

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

~
谢谢你的帮助

4

1 回答 1

3

我建议您不要花费数小时尝试正确配置 spork ,而是查看Zeus。很抱歉,如果这不能完全回答您的问题,但是我花了将近一年的时间使用 spork,每次添加新的测试 gem 时都在配置时遇到了很多麻烦,当我进行切换时,一切都神奇地起作用了(并且以我的经验,Zeus 的表现比 Spork 好得多)。

于 2013-08-02T14:31:33.380 回答