Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What testing tools and methods did Corey Haines use at GoGaRuCo 2011?

In this video from GoGaRuCo 2011, Corey Haines shows some techniques for making Rails test suites much faster. I would summarize it as follows:

  • Put as much of your code as possible outside the Rails app, into other modules and classes
  • Test those separately, without the overhead of loading up Rails
  • Use them from within your Rails app

There were a couple of things I didn't understand, though.

  • He alternates between running tests with rspec and spn or spna (for example, at about 3:50). Is spn a commonly-known tool?
  • In his tests for non-Rails classes and modules, he includes the module or class being tested, but I don't see him including anything like spec_helper. How does he have Rspec available?
like image 380
Nathan Long Avatar asked May 23 '12 19:05

Nathan Long


1 Answers

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.

like image 164
coreyhaines Avatar answered Sep 27 '22 19:09

coreyhaines