You need to tell RuboCop to load the RSpec extension. There are three ways to do this:
Put this into your
or, if you are using several extensions:
require: - rubocop-rspec - rubocop-performance
Now you can run
rubocop and it will automatically load the RuboCop RSpec
cops together with the standard cops.
In case you define aliases for RSpec DSL, i.e. examples, example groups, hooks, or include example statements, you need to configure it so those elements are properly detected by RuboCop RSpec.
# spec/spec_helper.rb RSpec.configure do |c| c.alias_example_group_to :detail, :detailed => true end # spec/detail_spec.rb RSpec.detail "a detail" do it "can do some less important stuff" do end end
# .rubocop.yml RSpec: Language: ExampleGroups: Regular: - detail
Some libraries extensively define RSpec DSL aliases (e.g. Pundit, Action Policy) or augment existing elements providing the same semantics (e.g.
Those libraries can provide necessary configuration, but won’t necessarily do so.
If they do, their README will mention that you have to explicitly require their configuration from your
# .rubocop.yml require: - rubocop-rspec - test-prof # or RSpec: Language: Helpers: - let_it_be
|the default merge mode is to inherit, so you won’t remove any of the default settings.|
RuboCop RSpec’s default configuration is a good source of information on what can be configured.
rubocop-rspec is available on Code Climate as part of the rubocop engine. Learn More.
rubocop-rspec only inspects code within paths ending in
_spec.rb or including
spec/. You can override this setting in your config file by setting
# Inspect files in `test/` directory RSpec: Include: - '**/test/**/*'
# Inspect only files ending with `_test.rb` RSpec: Include: - '**/*_test.rb'
Please keep in mind that merge mode for