rubocop-rspec 3.0.5 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/rspec/change_by_zero.rb +4 -3
- data/lib/rubocop/cop/rspec/context_wording.rb +15 -9
- data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
- data/lib/rubocop/cop/rspec/string_as_instance_double_constant.rb +45 -0
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +4 -1
- data/lib/rubocop/cop/rspec/void_expect.rb +6 -1
- data/lib/rubocop/cop/rspec_cops.rb +1 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c427b063cba22b4601d8244b18db288081f95889e287be82473e9148748c2e
|
4
|
+
data.tar.gz: 9d9543614cb00ee6cf4c94c750ce2368a4e34dae73f1a778e3fc9a7470698526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04fb1fe03b1fb818c7ee43d937fbb394e93a91e70c0cc00c06d259c53210ebb6b5243b584342838de566e99d0263d60b975113362b3a6306acf31f46ea2ed0ff
|
7
|
+
data.tar.gz: 66daeeaff0d894825dfcf0dc836b0fc614490b358b508ddaacc98652c37f0dc6e9c29e38222493e21a662f848a20efce503fe25a349b7a16fcc3693b9ecac4a1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 3.2.0 (2024-10-26)
|
6
|
+
|
7
|
+
- Fix `RSpec/VoidExpect` to only operate inside an example block. ([@corsonknowles])
|
8
|
+
- Change `RSpec/ContextWording` cop to always report an offense when both `Prefixes` and `AllowedPatterns` are empty. ([@ydah])
|
9
|
+
- Add support for `and` and `or` compound matchers to `RSpec/ChangeByZero` cop. ([@ydah])
|
10
|
+
|
11
|
+
## 3.1.0 (2024-10-01)
|
12
|
+
|
13
|
+
- Add `RSpec/StringAsInstanceDoubleConstant` to check for and correct strings used as instance_doubles. ([@corsonknowles])
|
14
|
+
- Fix false-positive for `RSpec/UnspecifiedException` when a method is literally named `raise_exception`. ([@aarestad])
|
15
|
+
- Fix false-positive for `RSpec/UnspecifiedException` when `not_to raise_error` is used within a block. ([@aarestad], [@G-Rath])
|
16
|
+
|
5
17
|
## 3.0.5 (2024-09-07)
|
6
18
|
|
7
19
|
- Fix false-negative and error for `RSpec/MetadataStyle` when non-literal args are used in metadata in `EnforceStyle: hash`. ([@cbliard])
|
@@ -899,6 +911,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
899
911
|
|
900
912
|
<!-- Contributors (alphabetically) -->
|
901
913
|
|
914
|
+
[@aarestad]: https://github.com/aarestad
|
902
915
|
[@abrom]: https://github.com/abrom
|
903
916
|
[@ahukkanen]: https://github.com/ahukkanen
|
904
917
|
[@akiomik]: https://github.com/akiomik
|
@@ -920,6 +933,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
920
933
|
[@cfabianski]: https://github.com/cfabianski
|
921
934
|
[@clupprich]: https://github.com/clupprich
|
922
935
|
[@composerinteralia]: https://github.com/composerinteralia
|
936
|
+
[@corsonknowles]: https://github.com/corsonknowles
|
923
937
|
[@corydiamand]: https://github.com/corydiamand
|
924
938
|
[@darhazer]: https://github.com/Darhazer
|
925
939
|
[@daveworth]: https://github.com/daveworth
|
data/config/default.yml
CHANGED
@@ -403,6 +403,7 @@ RSpec/ExampleWithoutDescription:
|
|
403
403
|
- single_line_only
|
404
404
|
- disallow
|
405
405
|
VersionAdded: '1.22'
|
406
|
+
StyleGuide: https://rspec.rubystyle.guide/#it-and-specify
|
406
407
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ExampleWithoutDescription
|
407
408
|
|
408
409
|
RSpec/ExampleWording:
|
@@ -929,6 +930,13 @@ RSpec/SpecFilePathSuffix:
|
|
929
930
|
- "**/spec/**/*"
|
930
931
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathSuffix
|
931
932
|
|
933
|
+
RSpec/StringAsInstanceDoubleConstant:
|
934
|
+
Description: Do not use a string as `instance_double` constant.
|
935
|
+
Enabled: pending
|
936
|
+
Safe: false
|
937
|
+
VersionAdded: '3.1'
|
938
|
+
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StringAsInstanceDoubleConstant
|
939
|
+
|
932
940
|
RSpec/StubbedMock:
|
933
941
|
Description: Checks that message expectations do not have a configured response.
|
934
942
|
Enabled: true
|
@@ -104,12 +104,12 @@ module RuboCop
|
|
104
104
|
# rubocop:disable Metrics/MethodLength
|
105
105
|
def register_offense(node, change_node)
|
106
106
|
if compound_expectations?(node)
|
107
|
-
add_offense(node
|
107
|
+
add_offense(node,
|
108
108
|
message: message_compound(change_node)) do |corrector|
|
109
109
|
autocorrect_compound(corrector, node)
|
110
110
|
end
|
111
111
|
else
|
112
|
-
add_offense(node
|
112
|
+
add_offense(node,
|
113
113
|
message: message(change_node)) do |corrector|
|
114
114
|
autocorrect(corrector, node, change_node)
|
115
115
|
end
|
@@ -118,7 +118,8 @@ module RuboCop
|
|
118
118
|
# rubocop:enable Metrics/MethodLength
|
119
119
|
|
120
120
|
def compound_expectations?(node)
|
121
|
-
|
121
|
+
node.parent.send_type? &&
|
122
|
+
%i[and or & |].include?(node.parent.method_name)
|
122
123
|
end
|
123
124
|
|
124
125
|
def message(change_node)
|
@@ -12,6 +12,9 @@ module RuboCop
|
|
12
12
|
#
|
13
13
|
# @see http://www.betterspecs.org/#contexts
|
14
14
|
#
|
15
|
+
# If both `Prefixes` and `AllowedPatterns` are empty, this cop will always
|
16
|
+
# report an offense. So you need to set at least one of them.
|
17
|
+
#
|
15
18
|
# @example `Prefixes` configuration
|
16
19
|
# # .rubocop.yml
|
17
20
|
# # RSpec/ContextWording:
|
@@ -58,7 +61,9 @@ module RuboCop
|
|
58
61
|
class ContextWording < Base
|
59
62
|
include AllowedPattern
|
60
63
|
|
61
|
-
|
64
|
+
MSG_MATCH = 'Context description should match %<patterns>s.'
|
65
|
+
MSG_ALWAYS = 'Current settings will always report an offense. Please ' \
|
66
|
+
'add allowed words to `Prefixes` or `AllowedPatterns`.'
|
62
67
|
|
63
68
|
# @!method context_wording(node)
|
64
69
|
def_node_matcher :context_wording, <<~PATTERN
|
@@ -67,8 +72,7 @@ module RuboCop
|
|
67
72
|
|
68
73
|
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
69
74
|
context_wording(node) do |context|
|
70
|
-
|
71
|
-
message = format(MSG, patterns: expect_patterns)
|
75
|
+
unless matches_allowed_pattern?(description(context))
|
72
76
|
add_offense(context, message: message)
|
73
77
|
end
|
74
78
|
end
|
@@ -84,12 +88,6 @@ module RuboCop
|
|
84
88
|
@prefix_regexes ||= prefixes.map { |pre| /^#{Regexp.escape(pre)}\b/ }
|
85
89
|
end
|
86
90
|
|
87
|
-
def bad_pattern?(node)
|
88
|
-
return false if allowed_patterns.empty?
|
89
|
-
|
90
|
-
!matches_allowed_pattern?(description(node))
|
91
|
-
end
|
92
|
-
|
93
91
|
def description(context)
|
94
92
|
if context.xstr_type?
|
95
93
|
context.value.value
|
@@ -98,6 +96,14 @@ module RuboCop
|
|
98
96
|
end
|
99
97
|
end
|
100
98
|
|
99
|
+
def message
|
100
|
+
if allowed_patterns.empty?
|
101
|
+
MSG_ALWAYS
|
102
|
+
else
|
103
|
+
format(MSG_MATCH, patterns: expect_patterns)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
101
107
|
def expect_patterns
|
102
108
|
inspected = allowed_patterns.map do |pattern|
|
103
109
|
pattern.inspect.gsub(/\A"|"\z/, '/')
|
@@ -69,7 +69,7 @@ module RuboCop
|
|
69
69
|
expect_literal(node) do |actual, send_node, matcher, expected|
|
70
70
|
next if SKIPPED_MATCHERS.include?(matcher)
|
71
71
|
|
72
|
-
add_offense(actual
|
72
|
+
add_offense(actual) do |corrector|
|
73
73
|
next unless CORRECTABLE_MATCHERS.include?(matcher)
|
74
74
|
next if literal?(expected)
|
75
75
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Do not use a string as `instance_double` constant.
|
7
|
+
#
|
8
|
+
# @safety
|
9
|
+
# This cop is unsafe because the correction requires loading the class.
|
10
|
+
# Loading before stubbing causes RSpec to only allow instance methods
|
11
|
+
# to be stubbed.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # bad
|
15
|
+
# instance_double('User', name: 'John')
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# instance_double(User, name: 'John')
|
19
|
+
#
|
20
|
+
class StringAsInstanceDoubleConstant < Base
|
21
|
+
extend AutoCorrector
|
22
|
+
|
23
|
+
MSG = 'Do not use a string as `instance_double` constant.'
|
24
|
+
RESTRICT_ON_SEND = %i[instance_double].freeze
|
25
|
+
|
26
|
+
# @!method stringified_instance_double_const?(node)
|
27
|
+
def_node_matcher :stringified_instance_double_const?, <<~PATTERN
|
28
|
+
(send nil? :instance_double $str ...)
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def on_send(node)
|
32
|
+
stringified_instance_double_const?(node) do |args_node|
|
33
|
+
add_offense(args_node) do |corrector|
|
34
|
+
autocorrect(corrector, args_node)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def autocorrect(corrector, node)
|
40
|
+
corrector.replace(node, node.value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -29,12 +29,14 @@ module RuboCop
|
|
29
29
|
|
30
30
|
def on_send(node)
|
31
31
|
return unless expect?(node)
|
32
|
+
return unless inside_example?(node)
|
32
33
|
|
33
34
|
check_expect(node)
|
34
35
|
end
|
35
36
|
|
36
37
|
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
37
38
|
return unless expect_block?(node)
|
39
|
+
return unless inside_example?(node)
|
38
40
|
|
39
41
|
check_expect(node)
|
40
42
|
end
|
@@ -49,11 +51,14 @@ module RuboCop
|
|
49
51
|
|
50
52
|
def void?(expect)
|
51
53
|
parent = expect.parent
|
52
|
-
return true unless parent
|
53
54
|
return true if parent.begin_type?
|
54
55
|
|
55
56
|
parent.block_type? && parent.body == expect
|
56
57
|
end
|
58
|
+
|
59
|
+
def inside_example?(node)
|
60
|
+
node.each_ancestor(:block).any? { |ancestor| example?(ancestor) }
|
61
|
+
end
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
@@ -99,6 +99,7 @@ require_relative 'rspec/skip_block_inside_example'
|
|
99
99
|
require_relative 'rspec/sort_metadata'
|
100
100
|
require_relative 'rspec/spec_file_path_format'
|
101
101
|
require_relative 'rspec/spec_file_path_suffix'
|
102
|
+
require_relative 'rspec/string_as_instance_double_constant'
|
102
103
|
require_relative 'rspec/stubbed_mock'
|
103
104
|
require_relative 'rspec/subject_declaration'
|
104
105
|
require_relative 'rspec/subject_stub'
|
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: 3.0
|
4
|
+
version: 3.2.0
|
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-10-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/rubocop/cop/rspec/sort_metadata.rb
|
158
158
|
- lib/rubocop/cop/rspec/spec_file_path_format.rb
|
159
159
|
- lib/rubocop/cop/rspec/spec_file_path_suffix.rb
|
160
|
+
- lib/rubocop/cop/rspec/string_as_instance_double_constant.rb
|
160
161
|
- lib/rubocop/cop/rspec/stubbed_mock.rb
|
161
162
|
- lib/rubocop/cop/rspec/subject_declaration.rb
|
162
163
|
- lib/rubocop/cop/rspec/subject_stub.rb
|