Question

I'm trying to speed up "rspecing" in a rails 2.3.8 app with spork. When I run spork in the root of the project I get:

(...stuff...)
No server is running
Running specs locally:
Spork is ready and listening on 8989!

And then, if I run specs, the message

 No server is running 
 Running specs locally 

which appears if I run them without Spork doesn't appear, however spec startup is as slow as without Spork. Also in Spork's terminal no further output appears.

My question is, is spork actually running? If so, are the specs running there?, and finally, if the answer to both is true, how can I speed up my tests?

Here are the config files involved:

spec/spec.opts

  --colour
  --format progress
  --loadby mtime
  --reverse
  --drb

spec/spec.helper

require 'rubygems'
require 'bundler/setup'
require 'spork'


Spork.prefork do

   ENV["RAILS_ENV"] ||= 'test'
   require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
   require 'spec/autorun'
   require 'spec/rails'

   Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}

   Spec::Runner.configure do |config|
  end


 end

 Spork.each_run do

end

And, to have a full question, here are the times measured with 'time':

With Spork:

real    0m39.524s
user    0m5.012s
sys  0m0.912s

Without Spork:

real    0m39.576s
user    0m18.537s
sys  0m2.400s

When running sport --diagnose I get

 - Spork Diagnosis -
 -- Summary --
 config/boot.rb
 config/initializers/inflections.rb
 config/initializers/mime_types.rb
 config/initializers/new_rails_defaults.rb
 config/initializers/site_keys.rb
 config/preinitializer.rb
 spec/spec_helper.rb

And then, for

 --- config/initializers/inflections.rb ---
 --- config/initializers/mime_types.rb ---
 --- config/initializers/new_rails_defaults.rb ---
 --- config/initializers/site_keys.rb ---

The following stacktrace

 /var/lib/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:147:in `load'
 /var/lib/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:622:in `load_application_initializers'
 /var/lib/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:621:in `each'
 /var/lib/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:621:in `load_application_initializers'
 /var/lib/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:176:in `process'
 /var/lib/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
 /var/lib/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in `run_without_spork'
 /var/lib/gems/1.8/gems/spork-0.8.4/lib/spork/app_framework/rails.rb:18:in `run'
 config/environment.rb:15
 spec/spec_helper.rb:14:in `require'
 spec/spec_helper.rb:14
 /var/lib/gems/1.8/gems/spork-0.8.4/bin/../lib/spork.rb:23:in `prefork'

spec/spec_helper.rb:6

Was it helpful?

Solution

I ran into the same problem, and this is what I was able to figure out.

Around line 50 of lib/tasks/rspec.rake you will find the following line.

spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop

This is causing db:test:prepare to get run before your specs, which in turn loads the environment, defeating the whole purpose of spork. I commented out this line and added the following below it.

spec_prereq = :noop

This change should result in quite a bit of improvement. You will have to run db:test:prepare manually after you run db:migrate. I have a command that does both.

I don't know whether you're using Bundler, but I saw additional speed gains by upgrading to the latest (1.0.7). (Bundler sets up load paths when Rake is loaded in 2.3.x)

I still have a ~2.5s delay resulting from the overhead of spork, rake, and bundler, which I hope can be improved in the future, perhaps when spork supports rails 3.

OTHER TIPS

The actions needed to enable spork are as follows :-

  1. add --drb to spec/spec.opts to tell spec to use drb to communicate with spork.
  2. Bootstrap spork using spork --bootstrap
  3. Modify spec/spec_helper.rb to setup spork

Have you done all of these three steps?

More information is available here

Your setup looks good to me. The lack of output is normal.

Did you try spork --diagnose? It should spit out a list of all the files spork preloads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top