title: Why do i get the following error? "Mysql2::Error: closed MySQL connection: SHOW TABLES"
body: <p>Using Spork, Rails3, RSpec2, Capybara, and FactoryGirl. </p>
  
  <p>While trying to execute a Capybara test I get the following error:</p>
  
  <pre><code> Failure/Error: model = FactoryGirl.create(:model)
      ActiveRecord::StatementInvalid:
        Mysql2::Error: closed MySQL connection: SHOW TABLES
  </code></pre>
  
  <p>The MySQL database that database.yml is using, is up and running. I can connect to it from the command line using the same settings in database.yml.</p>
  
  <p>The tests were working fine, I was trying to figure out why a test was failing and then it started giving this error.</p>
  
  <p>I've tried shutting down and restarting the database to no avail. </p>
  
  <p><strong>From database.yml</strong></p>
  
  <pre><code>test:
    adapter: mysql2
    encoding: utf8
    reconnect: false
    database: mysql_app_test
    pool: 5
    username: root
    password:
    host: localhost
  </code></pre>
  
  <p><strong>From my spec</strong></p>
  
  <pre><code>require 'spec_helper'
  
  describe "Model", :js =&gt; true do
  
    before(:each) do
      model = FactoryGirl.create(:model)
      visit model_path(model)
    end
  
    it "should show the button" do
      # Start the lesson
      find("#startButton")
    end
  end
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>It's also important to mention that I have been using <a href="http://pastie.org/1745020" rel="nofollow" title="solution 3">solution 3</a> to the <a href="https://groups.google.com/d/msg/ruby-capybara/JI6JrirL9gM/R6YiXj4gi_UJ" rel="nofollow">Capybara Transactional Fixtures Issue</a> associated with non Rack::Test drivers.</p>
  
  <p>I had placed my solution in my <strong>spec_helper.rb</strong> file like so:</p>
  
  <pre><code>Spork.prefork do
    ...
    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
    ...
  end
  </code></pre>
  
  <p>I had heard that there were similar <a href="http://opinionatedprogrammer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/#comment-815" rel="nofollow">issues when using solution 3 with spork</a> in a comment on <a href="http://opinionatedprogrammer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/#comment-220" rel="nofollow">solution 2</a>. I'm not sure if these are the issues the commenter mentioned.</p>