RSpec / Cucumber painfully slow Rails 3 OSX

I am working on my first Rails BDD project with extensive tests since
starting out with Rails a few years ago.

Running RSpec or Cucumber is really slow. I’m using Rails 3 and RSpec
2.
To run one model spec with only 5 tests takes almost 1 minute! When it
finishes it says it took only 0.9 seconds to run the actual test. So
obviously it is loading the environment that takes so long. I just
restarted my machine as I read somewhere that can make a difference,
but no joy for me.

Its very frustrating and time consuming - I am usually running tests
then going off to do something else while I wait for that to finish,
its really spoiling my work flow…! I read somewhere that even 15
seconds is a long time… 1 minute is ridiculous! Also that Java test
suites can run hundreds of examples in less than 2 seconds. I wish !!

I have looked into Spork, but this is not Rails 3 compatible yet.
Is there anything I can do to make this better?

Thanks in advance…

Ok - please excuse me - it seems that the info on the Spork readme is
out of date… the Rails 3 branch has been merged. just installed and
ran a test… wow… 1 minute had become 1 second!!

:slight_smile:

adam wrote in post #976260:

Ok - please excuse me - it seems that the info on the Spork readme is
out of date… the Rails 3 branch has been merged. just installed and
ran a test… wow… 1 minute had become 1 second!!

If you haven’t already done so, you might also take a look at the
following gems. This is what I have been using in my BDD workflow and
really speeds the process up for me.

autotest-standalone
autotest-rails-pure
autotest-fsevent
autotest-growl

I run this in a second terminal window and watch the Red-Green growl
notifications as I work through the Red-Green-Refactor cycle.

  1. If your running ‘rake spec’, then don’t, unless you need to do ‘rake
    db:test:prepare’ also. The ‘rake spec’ command combines the database
    rake with ‘rspec spec’, that’s why it takes a few seconds before the
    tests are run. Use ‘rspec spec’ instead.

  2. Use Spork and Autotest. Follow
    http://railstutorial.org/chapters/static-pages#sec:testing_tools to get
    Autotest setup. Note that you don’t need the Spork hack with the newest
    version of Spork.

  3. When using Autotest, consider removing ‘bundle exec’ from the RSpec
    command. In future versions of RSpec, you’ll be able to do this with a
    configuration setting, or you can get the current RSpec master which has
    committed the option already (see commit here
    https://github.com/rspec/rspec-core/commit/1ff93b0969a0f1a6c8d4cf39ed9b7466c7eb10c8).

If you want to freedom patch to get rid of ‘bundle exec’ see this post:
http://www.arailsdemo.com/posts/36. (There’s some other information in
the Post #35…)

I haven’t seen how these tips affect Cucumber yet, so you’ll have to
experiment on your own for now.

Arailsdemo A. wrote in post #976437:

  1. If your running ‘rake spec’, then don’t, unless you need to do ‘rake
    db:test:prepare’ also.

But don’t you always need to do that? Isn’t that the task that clears
out the test DB? Or is that not an issue since you’re (hopefully)
running your specs transactionally?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Sent from my iPhone

Thanks guys,

got autotest running now with the hack, working like a charm - now I
remember that sometimes I do actually enjoy coding! :slight_smile:

Now to get it working properly with Cucumber and Factory Girl
(“uninitialized constant Factory”) …

adam wrote in post #976772:

Now to get it working properly with Cucumber and Factory Girl
(“uninitialized constant Factory”) …

That could be a confusion between version 1.3 and 2.

Compare this:

https://github.com/thoughtbot/factory_girl#readme
https://github.com/thoughtbot/factory_girl/tree/1.3.x#readme

You could be looking at the 1.3 documentation (telling you to
use the Factory class), but installed version 2.0
(that has the FactoryGirl class).

HTH,

Peter

Thank you, but I still get the same error - “uninitialized constant
FactoryGirl (NameError)”

I have also posted on the FactoryGirl list:
https://groups.google.com/group/factory_girl/browse_thread/thread/8decccc21a97486?hl=en
(see bottom of the thread)

Regards
Adam

Strangely - I am not getting this error when running seperate
features, only when running just “cucucmber --drb”

But don’t you always need to do that? Isn’t that the task that clears
out the test DB? Or is that not an issue since you’re (hopefully)
running your specs transactionally?

As far as I can tell, the difference between ‘rake spec’ and ‘rspec
spec’ is ‘db:test:prepare’. When all tests pass with ‘rake spec’,
they’re also passing with ‘rspec spec’, only faster. If you check the
test database after running ‘rspec spec’, it should be empty. So that’s
why I think ‘rake spec’ isn’t necessary, unless the database schema has
changed.

I do have

    config.use_transactional_fixtures = true

in my spec_helper file. If the setting is set to false, then the
database could have residual data in it after running the tests.

Try adding this to your spec_helper.rb

Spork.each_run do
require ‘factory_girl_rails’
end

adam wrote in post #976883:

Strangely - I am not getting this error when running seperate
features, only when running just “cucucmber --drb”

Thank you - however that code it already in place…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs