This is an experiment for possible faster boot time (and consequently faster feedback) when running tests. I ask your help to try this in your apps (any Rails 3.x app) and let me know how well it works.
Add the following lines inside the configuration block in config/environments/test.rb
:
config.cache_classes = true
def eager_load!; end
Notice that config.cache_classes
needs to be true (which is the default), some tools may not be fine that. Needless to say, just do this for test environments.
The following two benches will work only for rspec running from the command line (hopefully you don't use rake to run your specs):
-
Pick up a spec file that runs all specs under 1s (for example, a file under spec/models or spec/helpers). Run the command below before and after you apply the
eager_load!
patch above (the bigger your application, the faster it should boot after you apply the patch):time rspec spec/models/SOME_MODEL_spec.rb
-
Try running your whole suite with and without the patch. In this case, you shouldn't see any perf difference and everything should work just fine (report if it doesn't!).
Let me know how 1) and 2) goes in the comments section below.
Tested it with 2 apps – a fairly big one (lots of models, controllers and mixins for both) with Rails 3.1.6 and a smaller one with 3.2.6. Both tests with Ruby 1.9.2-p290.
Rails 3.1.6 before patch
Finished in 1.07 seconds
8 examples, 0 failures
rspec spec/models/activity_spec.rb 13.88s user 2.05s system 94% cpu 16.829 total
Rails 3.1.6 after patch
Finished in 1.93 seconds
8 examples, 0 failures
rspec spec/models/activity_spec.rb 12.19s user 1.87s system 95% cpu 14.673 total
Rails 3.2.6 before patch
Finished in 0.87679 seconds
5 examples, 0 failures
rspec spec/models/cart_item_spec.rb 9.29s user 1.97s system 93% cpu 12.068 total
Rails 3.2.6 after patch
Finished in 0.90387 seconds
5 examples, 0 failures
rspec spec/models/cart_item_spec.rb 9.00s user 1.91s system 89% cpu 12.252 total