Search code examples
ruby-on-railsrspecspork

"PGError: no connection to the server" on running specs with Spork


I'm using Ruby 1.9.2, Rails 3.1, Rspec, Postgres and Spork, but I can't get them to play nicely together.

Running the specs for the first time (with Spork running in the background) works fine. However, when I run the specs a second time, it fails with:

Failure/Error: Unable to find matching line from backtrace
 PGError:
   no connection to the server
 # /Users/tom/.rvm/gems/ruby-1.9.2-p180@grapi/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:272:in `exec'
etc....

Any tips appreciated!


Solution

  • You probably also have Devise enabled.

    Your problem is described here: https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujutsu And more specifically for rails 3.1 here: https://gist.github.com/1054078

    The beginning of your prefork block in spec_helper.rb and env.rb should looks like:

    Spork.prefork do
      Spork.trap_method(Rails::Application, :reload_routes!)
      Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
    ...
    

    Good luck!