Add rubocop-rspec
In the spirit of https://gitlab.com/gitlab-org/gitlab-ce/issues/17406 and https://gitlab.com/gitlab-org/gitlab-ce/issues/17478, I found rubocop-rspec which has cops for a few things I'd like to automatically enforce, and I've got some other custom cop ideas we can add ourselves and/or send upstream.
This is its default configuration for 1.5.0, to which I've added inline notes:
# Probably not going to be able to enable this one easily
RSpec/AnyInstance:
Description: 'Check that instances are not being stubbed globally'
Enabled: true
RSpec/DescribeClass:
Description: 'Check that the first argument to the top level describe is the tested class or module.'
Enabled: true
# Hooray!
RSpec/DescribedClass:
Description: 'Use `described_class` for tested class / module'
Enabled: true
# We don't currently do this
RSpec/DescribeMethod:
Description: 'Checks that the second argument to top level describe is the tested method name.'
Enabled: true
# Nice to have but would likely require a lot of changes for not that much benefit
RSpec/ExampleWording:
Description: 'Do not use should when describing your tests.'
Enabled: true
CustomTransform:
be: is
have: has
not: does not
IgnoredWords: []
# Probably good to have
RSpec/MultipleDescribes:
Description: 'Checks for multiple top level describes.'
Enabled: true
# Good to have but also requires a lot of changes for some of our older specs
RSpec/InstanceVariable:
Description: 'Checks for the usage of instance variables.'
Enabled: true
RSpec/FilePath:
Description: 'Checks the file and folder naming of the spec file.'
Enabled: true
CustomTransform:
RuboCop: rubocop
RSpec: rspec
# Not sure, likely lots of offenses
RSpec/VerifiedDoubles:
Description: 'Prefer using verifying doubles over normal doubles.'
Enabled: true
IgnoreSymbolicNames: false
# Hooray!
RSpec/NotToNot:
Description: 'Enforces the usage of the same method on all negative message expectations.'
EnforcedStyle: not_to
SupportedStyles:
- not_to
- to_not
Enabled: true
# Sensible
RSpec/Focus:
Description: 'Checks if there are focused specs.'
Enabled: true
# Likely never going to happen
RSpec/ExampleLength:
Description: 'Checks for long example'
Enabled: true
Max: 5
I'll look into a custom cop for not supplying the default :each
argument to before
/ after
hooks, and would love to hear ideas for others.