Skip to content

Instantly share code, notes, and snippets.

@ianks

ianks/blog.md Secret

Created June 18, 2017 15:57
Show Gist options
  • Save ianks/8f2b4e5b7f447140ebc9841d79d6a9ee to your computer and use it in GitHub Desktop.
Save ianks/8f2b4e5b7f447140ebc9841d79d6a9ee to your computer and use it in GitHub Desktop.

Easily run next last failed spec in RSpec

The main reason I prefer using RSpec over alternatives like Minitest is that I find the CLI integration to be much more usable. Since RSpec 3.3, RSpec has offered the --next-failure feature. With this option, RSpec will only the first spec that failed. This is perfect for situations where diffs made some tests fail, or you just want to stay focused on the current failure.

In order to make this work, RSpec keeps some metadata about your previous runs. To enable this, add this to your spec_helper.rb:

https://gist.github.com/79549748dcb86ac91e86112aa6e0f5d7

Unfortunately, rspec --next-failure required a little too much typing for my liking. So as of RSpec 3.7, you can now just rspec -n. A small ergonomics improvement.

If you love writing well-tested, decoupled, happiness-inducing Ruby and React, we're hiring!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment