Skip to content

Commit 1adbcc6

Browse files
committed
Add explanation why RSpec/DescribedClass autocorrection is unsafe
1 parent 47f0330 commit 1adbcc6

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

docs/modules/ROOT/pages/cops_rspec.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,13 @@ To narrow down this setting to only a specific directory, it is
985985
possible to use an overriding configuration file local to that
986986
directory.
987987
988+
[#safety-rspecdescribedclass]
989+
=== Safety
990+
991+
Autocorrection is unsafe when `SkipBlocks: false` because
992+
`described_class` might not be available within the block (for
993+
example, in rspec-rails's `controller` helper).
994+
988995
[#examples-rspecdescribedclass]
989996
=== Examples
990997

lib/rubocop/cop/rspec/described_class.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ module RSpec
1313
# `OnlyStaticConstants` is only relevant when `EnforcedStyle` is
1414
# `described_class`.
1515
#
16+
# There's a known caveat with rspec-rails's `controller` helper that
17+
# runs its block in a different context, and `described_class` is not
18+
# available to it. `SkipBlocks` option excludes detection in all
19+
# non-RSpec related blocks.
20+
#
21+
# To narrow down this setting to only a specific directory, it is
22+
# possible to use an overriding configuration file local to that
23+
# directory.
24+
#
25+
# @safety
26+
# Autocorrection is unsafe when `SkipBlocks: false` because
27+
# `described_class` might not be available within the block (for
28+
# example, in rspec-rails's `controller` helper).
29+
#
1630
# @example `EnforcedStyle: described_class` (default)
1731
# # bad
1832
# describe MyClass do
@@ -47,15 +61,6 @@ module RSpec
4761
# subject { MyClass.do_something }
4862
# end
4963
#
50-
# There's a known caveat with rspec-rails's `controller` helper that
51-
# runs its block in a different context, and `described_class` is not
52-
# available to it. `SkipBlocks` option excludes detection in all
53-
# non-RSpec related blocks.
54-
#
55-
# To narrow down this setting to only a specific directory, it is
56-
# possible to use an overriding configuration file local to that
57-
# directory.
58-
#
5964
# @example `SkipBlocks: true`
6065
# # spec/controllers/.rubocop.yml
6166
# # RSpec/DescribedClass:

0 commit comments

Comments
 (0)