rubocop-rspec 2.27.0 → 2.27.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/config/default.yml +2 -1
- data/lib/rubocop/cop/rspec/described_class.rb +26 -5
- data/lib/rubocop/cop/rspec/repeated_subject_call.rb +14 -10
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 629669f9a1d9d41dae7bc62c630f3a6cdae80623d3213c8e79ac8eb207f79e59
|
4
|
+
data.tar.gz: 5005161c3684fcd8b794284bcaeedc50253a545d649be9e0e0a82958fdd125b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8af331d4b31697228397a1122cbe331223d3f040f44d2260e5148d73177df5ba08ae2aea1d481b27f698b5d59c9522d1c5f4c5e08e14b473a548de75ccf218c6
|
7
|
+
data.tar.gz: 0f86ea257bcd14e73c57b2e431f618e0959cf9dbeca6e22c4b75bd8d4945f670d8fdb65212ff12969b351b62c35f845ca28041d4b1b30627e7d64dda5932b365
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 2.27.1 (2024-03-03)
|
6
|
+
|
7
|
+
- Fix a false positive for `RSpec/RepeatedSubjectCall` when `subject.method_call`. ([@ydah])
|
8
|
+
- Add configuration option `OnlyStaticConstants` to `RSpec/DescribedClass`. ([@ydah])
|
9
|
+
|
5
10
|
## 2.27.0 (2024-03-01)
|
6
11
|
|
7
12
|
- Add new `RSpec/IsExpectedSpecify` cop. ([@ydah])
|
data/config/default.yml
CHANGED
@@ -283,9 +283,10 @@ RSpec/DescribedClass:
|
|
283
283
|
SupportedStyles:
|
284
284
|
- described_class
|
285
285
|
- explicit
|
286
|
+
OnlyStaticConstants: true
|
286
287
|
SafeAutoCorrect: false
|
287
288
|
VersionAdded: '1.0'
|
288
|
-
VersionChanged: '
|
289
|
+
VersionChanged: '2.27'
|
289
290
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
|
290
291
|
|
291
292
|
RSpec/DescribedClassModuleWrapping:
|
@@ -8,8 +8,10 @@ module RuboCop
|
|
8
8
|
# If the first argument of describe is a class, the class is exposed to
|
9
9
|
# each example via described_class.
|
10
10
|
#
|
11
|
-
# This cop can be configured using the `EnforcedStyle
|
12
|
-
# options.
|
11
|
+
# This cop can be configured using the `EnforcedStyle`, `SkipBlocks`
|
12
|
+
# and `OnlyStaticConstants` options.
|
13
|
+
# `OnlyStaticConstants` is only relevant when `EnforcedStyle` is
|
14
|
+
# `described_class`.
|
13
15
|
#
|
14
16
|
# @example `EnforcedStyle: described_class` (default)
|
15
17
|
# # bad
|
@@ -22,6 +24,18 @@ module RuboCop
|
|
22
24
|
# subject { described_class.do_something }
|
23
25
|
# end
|
24
26
|
#
|
27
|
+
# @example `OnlyStaticConstants: true` (default)
|
28
|
+
# # good
|
29
|
+
# describe MyClass do
|
30
|
+
# subject { MyClass::CONSTANT }
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# @example `OnlyStaticConstants: false`
|
34
|
+
# # bad
|
35
|
+
# describe MyClass do
|
36
|
+
# subject { MyClass::CONSTANT }
|
37
|
+
# end
|
38
|
+
#
|
25
39
|
# @example `EnforcedStyle: explicit`
|
26
40
|
# # bad
|
27
41
|
# describe MyClass do
|
@@ -54,7 +68,7 @@ module RuboCop
|
|
54
68
|
# end
|
55
69
|
# end
|
56
70
|
#
|
57
|
-
class DescribedClass < Base
|
71
|
+
class DescribedClass < Base # rubocop:disable Metrics/ClassLength
|
58
72
|
extend AutoCorrector
|
59
73
|
include ConfigurableEnforcedStyle
|
60
74
|
include Namespace
|
@@ -112,14 +126,17 @@ module RuboCop
|
|
112
126
|
|
113
127
|
def find_usage(node, &block)
|
114
128
|
yield(node) if offensive?(node)
|
115
|
-
|
116
|
-
return if scope_change?(node)
|
129
|
+
return if scope_change?(node) || allowed?(node)
|
117
130
|
|
118
131
|
node.each_child_node do |child|
|
119
132
|
find_usage(child, &block)
|
120
133
|
end
|
121
134
|
end
|
122
135
|
|
136
|
+
def allowed?(node)
|
137
|
+
node.const_type? && only_static_constants?
|
138
|
+
end
|
139
|
+
|
123
140
|
def message(offense)
|
124
141
|
if style == :described_class
|
125
142
|
format(MSG, replacement: DESCRIBED_CLASS, src: offense)
|
@@ -139,6 +156,10 @@ module RuboCop
|
|
139
156
|
node.block_type? && !rspec_block?(node) && cop_config['SkipBlocks']
|
140
157
|
end
|
141
158
|
|
159
|
+
def only_static_constants?
|
160
|
+
cop_config.fetch('OnlyStaticConstants', true)
|
161
|
+
end
|
162
|
+
|
142
163
|
def offensive?(node)
|
143
164
|
if style == :described_class
|
144
165
|
offensive_described_class?(node)
|
@@ -23,6 +23,12 @@ module RuboCop
|
|
23
23
|
# expect { my_method }.to not_change { A.count }
|
24
24
|
# end
|
25
25
|
#
|
26
|
+
# # also good
|
27
|
+
# it do
|
28
|
+
# expect { subject.a }.to change { A.count }
|
29
|
+
# expect { subject.b }.to not_change { A.count }
|
30
|
+
# end
|
31
|
+
#
|
26
32
|
class RepeatedSubjectCall < Base
|
27
33
|
include TopLevelGroup
|
28
34
|
|
@@ -64,17 +70,15 @@ module RuboCop
|
|
64
70
|
|
65
71
|
private
|
66
72
|
|
67
|
-
def detect_offense(
|
68
|
-
|
73
|
+
def detect_offense(subject_node)
|
74
|
+
return if subject_node.chained?
|
75
|
+
return unless (block_node = expect_block(subject_node))
|
69
76
|
|
70
|
-
|
71
|
-
|
77
|
+
add_offense(block_node)
|
78
|
+
end
|
72
79
|
|
73
|
-
|
74
|
-
|
75
|
-
return
|
76
|
-
end
|
77
|
-
end
|
80
|
+
def expect_block(node)
|
81
|
+
node.each_ancestor(:block).find { |block| block.method?(:expect) }
|
78
82
|
end
|
79
83
|
|
80
84
|
def detect_offenses_in_block(node, subject_names = [])
|
@@ -96,7 +100,7 @@ module RuboCop
|
|
96
100
|
|
97
101
|
subject_calls(node.body, Set[*subject_names, :subject]).each do |call|
|
98
102
|
if subjects_used[call.method_name]
|
99
|
-
detect_offense(
|
103
|
+
detect_offense(call)
|
100
104
|
else
|
101
105
|
subjects_used[call.method_name] = true
|
102
106
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.27.
|
4
|
+
version: 2.27.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-03-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
253
|
- !ruby/object:Gem::Version
|
254
254
|
version: '0'
|
255
255
|
requirements: []
|
256
|
-
rubygems_version: 3.
|
256
|
+
rubygems_version: 3.4.21
|
257
257
|
signing_key:
|
258
258
|
specification_version: 4
|
259
259
|
summary: Code style checking for RSpec files
|