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?
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!!
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.
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.
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.
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?
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.