RSpec shortcuts

. 1 min read

Some RSpec shortcuts I find useful.

Specify which tests to run

Append the line number to the spec file.

$ rspec my_spec.rb:89

I love this shortcut because it intelligently includes any appropriate contexts and hooks. It is a massive time saver.

Fail fast

Abort upon the first failing test. I use this setting in the CI, so failing builds don't clog the pipeline.

$ rspec my_spec.rb --fail-fast

Print failures eagerly

Rather than waiting for all specs to finish, you can print failures as they happen.

I really like eager failures, because I can start fixing issues before the test suite finishes. This is my default development setting.

To enable eager failures, install the rspec-print_failures_eagerly gem.

Photo by Mark Solarski on Unsplash.