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.
Ran two model spec files, one that loads rails, the other that only loads active record.
Doesn't appear to have made a noticeable difference on either. Still faster just not loading the whole app when running model specs. :)
BEFORE PATCH
loading whole app
ruby-1.9.2-p290@slottd[adding_slots]$ rspec spec/models/reservation_spec.rb
Finished in 0.3089 seconds
4 examples, 0 failures
real 0m12.956s
user 0m11.146s
sys 0m1.708s
loading only active record
ruby-1.9.2-p290@slottd[adding_slots*]$ rspec spec/models/event_spec.rb
Finished in 0.29744 seconds
11 examples, 0 failures
real 0m1.830s
user 0m1.340s
sys 0m0.479s
AFTER PATCH
loading whole app
ruby-1.9.2-p290@slottd[adding_slots*]$ rspec spec/models/reservation_spec.rb
Finished in 0.37295 seconds
4 examples, 0 failures
real 0m12.642s
user 0m10.877s
sys 0m1.700s
loading only active record
ruby-1.9.2-p290@slottd[adding_slots*]$ rspec spec/models/event_spec.rb
Finished in 0.29604 seconds
11 examples, 0 failures
real 0m1.825s
user 0m1.336s
sys 0m0.476s