Why not use shared ActiveRecord connections for Rspec + Selenium?

Actually there are issues with it. If you use the gem mysql2, for example, you’ll start seeing some errors like:

Mysql2::Error This connection is still waiting for a result

Please use this instead. It was written by Mike Perham, all credits to him.

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
  end
end

ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

You’ll need to install gem connection_pool too.
This will spare you from many headaches.

Leave a Comment