Skip to content

Commit

Permalink
fixup! Note to use :config in custom cop specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Nov 3, 2020
1 parent fa78d97 commit 1e499d2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/modules/ROOT/pages/upgrade_to_version_2.adoc
Expand Up @@ -10,6 +10,7 @@ In version 2.x:
- cop departments are nested for cops with a department that doesn’t match the extension name (`Capybara`, `FactoryBot`, `Rails`)
- `AllCops/RSpec/Patterns`/`AllCops/FactoryBot/Patterns` options are removed
- Calling `super` from `on_new_investigation` defined in a cop is mandatory now
- Avoid explicit definition of `cop` as `described_class.new`

[discrete]
=== Adjust the configuration of `RSpec/EmptyExampleGroup`
Expand Down Expand Up @@ -241,6 +242,30 @@ end

https://github.com/rubocop-hq/rubocop-rspec/pull/956[Pull request with more examples].

=== Use `:config` RSpec metadata in cop specs

`:config` metadata should be added to the top-level example group of your cop spec.
Doing otherwise will not pass configuration to the cop, and dynamic RSpec DSL matchers might not work.

[source,ruby]
----
# Before
RSpec.describe 'MyMightyCop' do
let(:cop) { described_class.new }
# ...
end
# After
RSpec.describe 'MyMightyCop', :config do
# `cop` is defined for you by RuboCop's shared context that is included
# to example groups with :config metadata
# ...
end
----

https://github.com/rubocop-hq/rubocop/blob/51ff1d7e29c985732fe129082c98d66c531a2611/lib/rubocop/rspec/shared_contexts.rb#L56[RuboCop takes care of defining everything for your cop specs].

=== Conform with RuboCop API Changes

The parent project, RuboCop, has API changes.
Expand Down

0 comments on commit 1e499d2

Please sign in to comment.