Skip to content

Commit 1e499d2

Browse files
committed
fixup! Note to use :config in custom cop specs
1 parent fa78d97 commit 1e499d2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/modules/ROOT/pages/upgrade_to_version_2.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ In version 2.x:
1010
- cop departments are nested for cops with a department that doesn’t match the extension name (`Capybara`, `FactoryBot`, `Rails`)
1111
- `AllCops/RSpec/Patterns`/`AllCops/FactoryBot/Patterns` options are removed
1212
- Calling `super` from `on_new_investigation` defined in a cop is mandatory now
13+
- Avoid explicit definition of `cop` as `described_class.new`
1314

1415
[discrete]
1516
=== Adjust the configuration of `RSpec/EmptyExampleGroup`
@@ -241,6 +242,30 @@ end
241242

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

245+
=== Use `:config` RSpec metadata in cop specs
246+
247+
`:config` metadata should be added to the top-level example group of your cop spec.
248+
Doing otherwise will not pass configuration to the cop, and dynamic RSpec DSL matchers might not work.
249+
250+
[source,ruby]
251+
----
252+
# Before
253+
RSpec.describe 'MyMightyCop' do
254+
let(:cop) { described_class.new }
255+
# ...
256+
end
257+
258+
# After
259+
RSpec.describe 'MyMightyCop', :config do
260+
# `cop` is defined for you by RuboCop's shared context that is included
261+
# to example groups with :config metadata
262+
263+
# ...
264+
end
265+
----
266+
267+
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].
268+
244269
=== Conform with RuboCop API Changes
245270

246271
The parent project, RuboCop, has API changes.

0 commit comments

Comments
 (0)