エラー名
rspec --drb spec
で実行すると下のようなエラーが出た。
ActiveRecord::ConnectionNotEstablished
対処法
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"
config.include Capybara::DSL
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
end
Spork.each_run do
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection # 多分ここが重要らしい!!
end
ファイルを追加する
spec/support/shared_connection.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
これで動くようになる(^^ゞ!!