Inspired by this post on RSpec best practices and updated for RSpec2.
We’re rapidly approaching 2000 tests in our main project, adding about 100 tests every week. Everyone got really crafty at figuring out the optimal terminal window width to make the twenty or so rows of green and yellow dots from RSpec progress to align nicely. So we replaced the RSpec formatter with the awesome Fuubar (see introductory post) which now gives us ETA and shows error details as they appear. Nice.
The really annoying part of RSpec is that tests can run in any order. This depends on file timestamps as RSpec globs the files. What I’d really want is to run short domain model tests first and long UI Capybara tests last. This way I’ll be catching errors sooner. Let’s break the tests up into suites. Add lib/tasks/test_suites.rake. Note that pattern can take an array and that this actually generates Rake tasks.
Run rake -T
for a list of generated tasks. We can now run rake spec:suite:all
or individual suites with, for example, rake spec:suite:models
.