Search code examples
rubyruby-on-rails-3tdddatamapperrspec-rails

Rspec takes too long to load


I am using Rspec with my Rails 3.2.11 app. I have installed and set up spork. I use datamapper as ORM.

Yet when spork is running, a running a single test takes more than a minute. Even if the test being run is empty. Something is surely wrong. But I cannot figure out what exactly.

My test_spec is as this:

require "spec_helper"
require "cancan/matchers"

describe User do
end

My spec helper file can be found here: https://gist.github.com/4593609

When I time the rspec:

➜  books git:(dev) ✗ time rspec --drb spec/models/test_spec.rb
No examples found.


Finished in 1 minute 51.08 seconds
0 examples, 0 failures
rspec --drb spec/models/test_spec.rb  1.49s user 0.04s system 1% cpu 1:52.94 total

Spork Log:

➜  books git:(dev) ✗ spork
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Rack::File headers parameter replaces cache_control after Rack 1.5.
Spork is ready and listening on 8989!
Running tests with args ["spec/models/test_spec.rb"]...
Done.

Running tests with args ["spec/models/test_spec.rb"]...
Done.

This is for an empty spec. It takes more time for specs with lots of examples. What can be taking so long for it to run ?


Solution

  • I found a solution for this problem. The problem was in my spec_helper file.

     config.before(:suite) {
       DataMapper.auto_upgrade!
     }
    

    Because of these configs, Datamapper was trying to autoupgrade each time I ran the test. On commenting this config, spec started working normally even when spork is not running.