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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ce22630f88fd7a9b996711a4af330a186471fdc8a6dd99b05830ad695a09118
4
- data.tar.gz: 44a91f15e435ec623b2a25ae6e7b890772d7cf3066206f97b0ca1abf42c62c7a
3
+ metadata.gz: 511453cda141040130409ba47cb96cf41f559d86a2b30c57e3dffdde43bafa9c
4
+ data.tar.gz: 18e0e3e3b2f2db53205526ab5561f3892fa19b3fbff890e8b2707bb1b8ab9c5b
5
5
  SHA512:
6
- metadata.gz: 0d6b6f4113c4fc5253dcd59525e348879ae5763d09bb416de752d037b3ee20c38774df54322a8c7abd4c21652b22e6c4ac708bce51a2f1df61fecb4aab9dc4ac
7
- data.tar.gz: ec0278b64e0dc0ca9cf0e9558ae02224ea5a3360ee86380336b4bc07e134801e46011f5ef673586eac6b85557884b3d3986d05935b3255ba48c227ecd760227c
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.source_range,
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.source_range,
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.source_range) do |corrector|
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
@@ -62,7 +62,10 @@ module RuboCop
62
62
  end
63
63
 
64
64
  def find_expect_to(node)
65
- node.each_ancestor(:send).find do |ancestor|
65
+ node.each_ancestor.find do |ancestor|
66
+ break if ancestor.block_type?
67
+ next unless ancestor.send_type?
68
+
66
69
  expect_to?(ancestor)
67
70
  end
68
71
  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'
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '3.0.5'
7
+ STRING = '3.1.0'
8
8
  end
9
9
  end
10
10
  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: 3.0.5
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-09-07 00:00:00.000000000 Z
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