You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/upgrade_to_version_2.adoc
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ In version 2.x:
10
10
- cop departments are nested for cops with a department that doesn’t match the extension name (`Capybara`, `FactoryBot`, `Rails`)
11
11
- `AllCops/RSpec/Patterns`/`AllCops/FactoryBot/Patterns` options are removed
12
12
- Calling `super` from `on_new_investigation` defined in a cop is mandatory now
13
+
- Avoid explicit definition of `cop` as `described_class.new`
13
14
14
15
[discrete]
15
16
=== Adjust the configuration of `RSpec/EmptyExampleGroup`
@@ -241,6 +242,30 @@ end
241
242
242
243
https://github.com/rubocop-hq/rubocop-rspec/pull/956[Pull request with more examples].
243
244
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].
0 commit comments