In this video from GoGaRuCo 2011, Corey Haines shows some techniques for making Rails test suites much faster. I would summarize it as follows:
There were a couple of things I didn't understand, though.
rspec
and spn
or spna
(for example, at about 3:50). Is spn
a commonly-known tool?spec_helper
. How does he have Rspec available?Sorry about the confusion. spn
and spna
are aliases I have that add my non-rails code to rspec's load path. There isn't anything special about them, other than adding a -I path_to_code
on the command-line.
These days, I add something like this to my .rspec
file:
-I app/mercury_app
Then I can do simple require 'object_name'
at the top of my specs.
As for not including spec_helper
: that is true, I don't. When you execute your spec file with rspec <path_to_spec_file>
, it gets interpreted, so you don't need to require rspec
explicitly.
For my db specs these days, I also have built an active_record_spec_helper
which requires active_record, establishes a connection to the test database, and sets up database_cleaner
; this allows me to simply require my model at the top of my spec file. This way, I can test the AR code against the db without having to load up my whole app.
A client I am working at where we are using these techniques is interested in supporting some blog posts about this, so hopefully they will start coming out towards the middle of June.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With