Monday, August 25, 2008

Rspec format options

Although I use autotest and Textmate (CMD+R is second nature now) when I'm writing Rspec tests, once in a while I'll run a good old 'rake spec' from the console just before I do a git commit. The default behaviour for Rspec is to show the progression of tests as green dots, or F's (see 'progress' example below), but there are many more options as well.

Rspec has many different output formats to choose from, however you can only define one format to be printed to the console. If you want any more formats to be printed, you'll have to output them to a file (explained next).

To modify your Rspec options, you need to edit your RAILS_ROOT/spec/spec.opts file. Here's one of my files to show as an example:

--colour
--format progress
--format specdoc:spec/spec_full_report.txt
--format failing_examples:spec/spec_failing_examples.txt
--format html:spec/spec_report.html
--loadby mtime
--reverse

As you can see here, there are 4 formats defined; the one that's being printed to the console is 'progress', and specdoc, failing_examples (outputs the name of the failing examples), and html are all being outputted to separate files in the spec folder. Just follow the "format:file_output_name" convention and everything should work. Here are some examples of the different formats.

'progress' - default output format (--format progress):


'specdoc' - detailed output format (--format specdoc):


'html' - HTML output format / Textmate (--format html:spec/spec_report.html):

No comments: