You might already be using RSpec’s .rspec file to avoid having to add the require 'spec_helper' line at the top of all your spec files.

But did you know that RSpec supports ERB in the .rspec file?

Which means you can make your .rspec file this:

--require spec_helper
<%= "--require byebug" unless ENV["CI"] %>

in order to:

  • always load byebug when running tests on your local machine so you don’t have to add require 'byebug' every time you need to start a debugger with byebug
  • skip loading byebug during your Continuous Integration (CI) builds (assuming your CI server sets the CI environment variable like Travis CI does)
  • fail your CI builds fast whenever you accidentally leave in a call to byebug (instead of hanging waiting for input until eventually timing out)