rubocop-rspec 3.0.5 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/config/default.yml +7 -0
- data/lib/rubocop/cop/rspec/change_by_zero.rb +2 -2
- 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_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: 511453cda141040130409ba47cb96cf41f559d86a2b30c57e3dffdde43bafa9c
|
4
|
+
data.tar.gz: 18e0e3e3b2f2db53205526ab5561f3892fa19b3fbff890e8b2707bb1b8ab9c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5189eeedb66e02e5d6ca0423983dc729e03fbd718280d3882b5225cf4e986a518c628e7fdb8bc13ae5772448d30b05759654edfb9595b7b2cb8fe75a5207c849
|
7
|
+
data.tar.gz: 2cd44d42228da314c16e0f074f5768c6168daa4407d67ebc7f7740536af12bf90ca907cd72b987659a6e4ac09a26c1c26a4af21585274d1da4af19873d0f86dd
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## Master (Unreleased)
|
4
4
|
|
5
|
+
## 3.1.0 (2024-10-01)
|
6
|
+
|
7
|
+
- Add `RSpec/StringAsInstanceDoubleConstant` to check for and correct strings used as instance_doubles. ([@corsonknowles])
|
8
|
+
- Fix false-positive for `RSpec/UnspecifiedException` when a method is literally named `raise_exception`. ([@aarestad])
|
9
|
+
- Fix false-positive for `RSpec/UnspecifiedException` when `not_to raise_error` is used within a block. ([@aarestad], [@G-Rath])
|
10
|
+
|
5
11
|
## 3.0.5 (2024-09-07)
|
6
12
|
|
7
13
|
- Fix false-negative and error for `RSpec/MetadataStyle` when non-literal args are used in metadata in `EnforceStyle: hash`. ([@cbliard])
|
@@ -899,6 +905,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
899
905
|
|
900
906
|
<!-- Contributors (alphabetically) -->
|
901
907
|
|
908
|
+
[@aarestad]: https://github.com/aarestad
|
902
909
|
[@abrom]: https://github.com/abrom
|
903
910
|
[@ahukkanen]: https://github.com/ahukkanen
|
904
911
|
[@akiomik]: https://github.com/akiomik
|
@@ -920,6 +927,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
|
|
920
927
|
[@cfabianski]: https://github.com/cfabianski
|
921
928
|
[@clupprich]: https://github.com/clupprich
|
922
929
|
[@composerinteralia]: https://github.com/composerinteralia
|
930
|
+
[@corsonknowles]: https://github.com/corsonknowles
|
923
931
|
[@corydiamand]: https://github.com/corydiamand
|
924
932
|
[@darhazer]: https://github.com/Darhazer
|
925
933
|
[@daveworth]: https://github.com/daveworth
|
data/config/default.yml
CHANGED
@@ -929,6 +929,13 @@ RSpec/SpecFilePathSuffix:
|
|
929
929
|
- "**/spec/**/*"
|
930
930
|
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SpecFilePathSuffix
|
931
931
|
|
932
|
+
RSpec/StringAsInstanceDoubleConstant:
|
933
|
+
Description: Do not use a string as `instance_double` constant.
|
934
|
+
Enabled: pending
|
935
|
+
Safe: false
|
936
|
+
VersionAdded: '3.1'
|
937
|
+
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/StringAsInstanceDoubleConstant
|
938
|
+
|
932
939
|
RSpec/StubbedMock:
|
933
940
|
Description: Checks that message expectations do not have a configured response.
|
934
941
|
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
|
@@ -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
|
@@ -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.1.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-01 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
|