Rubocop and Capybara: detecting forgotten focus: :true

Viewed 436

As a Rails developper, I got used to work with Rubocop on my CI, and one of the basic feature I like is the detection of forgotten debugger entries, like byebug.

There is another string that can easily be forgotten: :focus or focus: :true in Capybara feature specs. It just happened in my team, and we are looking for a way to prevent it.

I have seen rubocop-rspec, but apparently that case is not covered.

What is the most efficient option?

2 Answers

Rubocop already checks for focus: true and :focus. Make sure your team didn't disable the cop.

# bad
describe MyClass, focus: true do
end

# bad
describe MyClass, :focus do
end

# good
fdescribe MyClass do
end

# good
describe MyClass do
end

It's a good idea to configure RSpec to ignore :focus when on CI too - so all your tests get run even if a lingering :focus is left behind. For instance that can be done on Travis with

RSpec.configure do |config|
  config.filter_run_including focus: true unless ENV['TRAVIS']
  config.run_all_when_everything_filtered = true
end
Related