rubocop-rspec 2.22.0 → 2.27.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +94 -9
  3. data/README.md +1 -1
  4. data/config/default.yml +126 -21
  5. data/lib/rubocop/cop/rspec/around_block.rb +3 -3
  6. data/lib/rubocop/cop/rspec/be.rb +1 -1
  7. data/lib/rubocop/cop/rspec/be_empty.rb +1 -0
  8. data/lib/rubocop/cop/rspec/be_eq.rb +1 -1
  9. data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
  10. data/lib/rubocop/cop/rspec/be_nil.rb +2 -2
  11. data/lib/rubocop/cop/rspec/before_after_all.rb +7 -13
  12. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +2 -2
  13. data/lib/rubocop/cop/rspec/change_by_zero.rb +30 -4
  14. data/lib/rubocop/cop/rspec/context_method.rb +2 -2
  15. data/lib/rubocop/cop/rspec/context_wording.rb +1 -1
  16. data/lib/rubocop/cop/rspec/describe_symbol.rb +1 -1
  17. data/lib/rubocop/cop/rspec/described_class.rb +33 -11
  18. data/lib/rubocop/cop/rspec/duplicated_metadata.rb +1 -1
  19. data/lib/rubocop/cop/rspec/empty_example_group.rb +4 -1
  20. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +2 -2
  21. data/lib/rubocop/cop/rspec/empty_metadata.rb +46 -0
  22. data/lib/rubocop/cop/rspec/eq.rb +47 -0
  23. data/lib/rubocop/cop/rspec/example_length.rb +11 -5
  24. data/lib/rubocop/cop/rspec/example_without_description.rb +11 -2
  25. data/lib/rubocop/cop/rspec/example_wording.rb +11 -2
  26. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +14 -5
  27. data/lib/rubocop/cop/rspec/expect_actual.rb +7 -4
  28. data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
  29. data/lib/rubocop/cop/rspec/expect_output.rb +1 -4
  30. data/lib/rubocop/cop/rspec/file_path.rb +6 -0
  31. data/lib/rubocop/cop/rspec/focus.rb +17 -2
  32. data/lib/rubocop/cop/rspec/hook_argument.rb +2 -2
  33. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -1
  34. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +2 -2
  35. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
  36. data/lib/rubocop/cop/rspec/implicit_subject.rb +2 -2
  37. data/lib/rubocop/cop/rspec/indexed_let.rb +32 -1
  38. data/lib/rubocop/cop/rspec/instance_spy.rb +2 -2
  39. data/lib/rubocop/cop/rspec/instance_variable.rb +3 -3
  40. data/lib/rubocop/cop/rspec/is_expected_specify.rb +45 -0
  41. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -3
  42. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -1
  43. data/lib/rubocop/cop/rspec/let_before_examples.rb +5 -1
  44. data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
  45. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -2
  46. data/lib/rubocop/cop/rspec/message_spies.rb +0 -2
  47. data/lib/rubocop/cop/rspec/metadata_style.rb +202 -0
  48. data/lib/rubocop/cop/rspec/mixin/file_help.rb +14 -0
  49. data/lib/rubocop/cop/rspec/mixin/metadata.rb +21 -7
  50. data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +2 -2
  51. data/lib/rubocop/cop/rspec/multiple_expectations.rb +12 -7
  52. data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
  53. data/lib/rubocop/cop/rspec/pending.rb +12 -2
  54. data/lib/rubocop/cop/rspec/pending_without_reason.rb +1 -1
  55. data/lib/rubocop/cop/rspec/predicate_matcher.rb +9 -9
  56. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +1 -1
  57. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +34 -10
  58. data/lib/rubocop/cop/rspec/rails/http_status.rb +29 -18
  59. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +314 -22
  60. data/lib/rubocop/cop/rspec/rails/negation_be_valid.rb +102 -0
  61. data/lib/rubocop/cop/rspec/receive_counts.rb +1 -1
  62. data/lib/rubocop/cop/rspec/receive_messages.rb +161 -0
  63. data/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb +67 -0
  64. data/lib/rubocop/cop/rspec/remove_const.rb +40 -0
  65. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +1 -1
  66. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +2 -2
  67. data/lib/rubocop/cop/rspec/repeated_include_example.rb +1 -1
  68. data/lib/rubocop/cop/rspec/repeated_subject_call.rb +124 -0
  69. data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -1
  70. data/lib/rubocop/cop/rspec/shared_context.rb +1 -1
  71. data/lib/rubocop/cop/rspec/shared_examples.rb +66 -20
  72. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +2 -3
  73. data/lib/rubocop/cop/rspec/sort_metadata.rb +2 -1
  74. data/lib/rubocop/cop/rspec/spec_file_path_format.rb +133 -0
  75. data/lib/rubocop/cop/rspec/spec_file_path_suffix.rb +40 -0
  76. data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -1
  77. data/lib/rubocop/cop/rspec/subject_stub.rb +4 -4
  78. data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -2
  79. data/lib/rubocop/cop/rspec/variable_definition.rb +4 -4
  80. data/lib/rubocop/cop/rspec/verified_double_reference.rb +6 -6
  81. data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
  82. data/lib/rubocop/cop/rspec/void_expect.rb +4 -3
  83. data/lib/rubocop/cop/rspec_cops.rb +11 -0
  84. data/lib/rubocop/rspec/language.rb +8 -8
  85. data/lib/rubocop/rspec/version.rb +1 -1
  86. data/lib/rubocop/rspec/wording.rb +8 -0
  87. data/lib/rubocop-rspec.rb +1 -0
  88. metadata +20 -8
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module RSpec
6
6
  # Prefer using verifying doubles over normal doubles.
7
7
  #
8
- # @see https://relishapp.com/rspec/rspec-mocks/docs/verifying-doubles
8
+ # @see https://rspec.info/features/3-12/rspec-mocks/verifying-doubles
9
9
  #
10
10
  # @example
11
11
  # # bad
@@ -28,7 +28,7 @@ module RuboCop
28
28
  RESTRICT_ON_SEND = %i[double spy].freeze
29
29
 
30
30
  # @!method unverified_double(node)
31
- def_node_matcher :unverified_double, <<-PATTERN
31
+ def_node_matcher :unverified_double, <<~PATTERN
32
32
  {(send nil? {:double :spy} $...)}
33
33
  PATTERN
34
34
 
@@ -18,12 +18,12 @@ module RuboCop
18
18
  RESTRICT_ON_SEND = %i[expect].freeze
19
19
 
20
20
  # @!method expect?(node)
21
- def_node_matcher :expect?, <<-PATTERN
21
+ def_node_matcher :expect?, <<~PATTERN
22
22
  (send nil? :expect ...)
23
23
  PATTERN
24
24
 
25
25
  # @!method expect_block?(node)
26
- def_node_matcher :expect_block?, <<-PATTERN
26
+ def_node_matcher :expect_block?, <<~PATTERN
27
27
  (block #expect? (args) _body)
28
28
  PATTERN
29
29
 
@@ -51,7 +51,8 @@ module RuboCop
51
51
  parent = expect.parent
52
52
  return true unless parent
53
53
  return true if parent.begin_type?
54
- return true if parent.block_type? && parent.body == expect
54
+
55
+ parent.block_type? && parent.body == expect
55
56
  end
56
57
  end
57
58
  end
@@ -18,6 +18,7 @@ require_relative 'rspec/factory_bot/syntax_methods'
18
18
 
19
19
  require_relative 'rspec/rails/avoid_setup_hook'
20
20
  require_relative 'rspec/rails/have_http_status'
21
+ require_relative 'rspec/rails/negation_be_valid'
21
22
  begin
22
23
  require_relative 'rspec/rails/http_status'
23
24
  rescue LoadError
@@ -56,6 +57,8 @@ require_relative 'rspec/empty_line_after_example_group'
56
57
  require_relative 'rspec/empty_line_after_final_let'
57
58
  require_relative 'rspec/empty_line_after_hook'
58
59
  require_relative 'rspec/empty_line_after_subject'
60
+ require_relative 'rspec/empty_metadata'
61
+ require_relative 'rspec/eq'
59
62
  require_relative 'rspec/example_length'
60
63
  require_relative 'rspec/example_without_description'
61
64
  require_relative 'rspec/example_wording'
@@ -75,6 +78,7 @@ require_relative 'rspec/implicit_subject'
75
78
  require_relative 'rspec/indexed_let'
76
79
  require_relative 'rspec/instance_spy'
77
80
  require_relative 'rspec/instance_variable'
81
+ require_relative 'rspec/is_expected_specify'
78
82
  require_relative 'rspec/it_behaves_like'
79
83
  require_relative 'rspec/iterated_expectation'
80
84
  require_relative 'rspec/leading_subject'
@@ -85,6 +89,7 @@ require_relative 'rspec/match_array'
85
89
  require_relative 'rspec/message_chain'
86
90
  require_relative 'rspec/message_expectation'
87
91
  require_relative 'rspec/message_spies'
92
+ require_relative 'rspec/metadata_style'
88
93
  require_relative 'rspec/missing_example_group_argument'
89
94
  require_relative 'rspec/multiple_describes'
90
95
  require_relative 'rspec/multiple_expectations'
@@ -99,13 +104,17 @@ require_relative 'rspec/pending'
99
104
  require_relative 'rspec/pending_without_reason'
100
105
  require_relative 'rspec/predicate_matcher'
101
106
  require_relative 'rspec/receive_counts'
107
+ require_relative 'rspec/receive_messages'
102
108
  require_relative 'rspec/receive_never'
103
109
  require_relative 'rspec/redundant_around'
110
+ require_relative 'rspec/redundant_predicate_matcher'
111
+ require_relative 'rspec/remove_const'
104
112
  require_relative 'rspec/repeated_description'
105
113
  require_relative 'rspec/repeated_example'
106
114
  require_relative 'rspec/repeated_example_group_body'
107
115
  require_relative 'rspec/repeated_example_group_description'
108
116
  require_relative 'rspec/repeated_include_example'
117
+ require_relative 'rspec/repeated_subject_call'
109
118
  require_relative 'rspec/return_from_stub'
110
119
  require_relative 'rspec/scattered_let'
111
120
  require_relative 'rspec/scattered_setup'
@@ -114,6 +123,8 @@ require_relative 'rspec/shared_examples'
114
123
  require_relative 'rspec/single_argument_message_chain'
115
124
  require_relative 'rspec/skip_block_inside_example'
116
125
  require_relative 'rspec/sort_metadata'
126
+ require_relative 'rspec/spec_file_path_format'
127
+ require_relative 'rspec/spec_file_path_suffix'
117
128
  require_relative 'rspec/stubbed_mock'
118
129
  require_relative 'rspec/subject_declaration'
119
130
  require_relative 'rspec/subject_stub'
@@ -42,7 +42,7 @@ module RuboCop
42
42
  PATTERN
43
43
 
44
44
  # @!method example_group_with_body?(node)
45
- def_node_matcher :example_group_with_body?, <<-PATTERN
45
+ def_node_matcher :example_group_with_body?, <<~PATTERN
46
46
  (block (send #rspec? #ExampleGroups.all ...) args !nil?)
47
47
  PATTERN
48
48
 
@@ -50,15 +50,15 @@ module RuboCop
50
50
  def_node_matcher :example?, '(block (send nil? #Examples.all ...) ...)'
51
51
 
52
52
  # @!method hook?(node)
53
- def_node_matcher :hook?, <<-PATTERN
54
- {
55
- (numblock (send nil? #Hooks.all ...) ...)
56
- (block (send nil? #Hooks.all ...) ...)
57
- }
53
+ def_node_matcher :hook?, <<~PATTERN
54
+ {
55
+ (numblock (send nil? #Hooks.all ...) ...)
56
+ (block (send nil? #Hooks.all ...) ...)
57
+ }
58
58
  PATTERN
59
59
 
60
60
  # @!method let?(node)
61
- def_node_matcher :let?, <<-PATTERN
61
+ def_node_matcher :let?, <<~PATTERN
62
62
  {
63
63
  (block (send nil? #Helpers.all ...) ...)
64
64
  (send nil? #Helpers.all _ block_pass)
@@ -66,7 +66,7 @@ module RuboCop
66
66
  PATTERN
67
67
 
68
68
  # @!method include?(node)
69
- def_node_matcher :include?, <<-PATTERN
69
+ def_node_matcher :include?, <<~PATTERN
70
70
  {
71
71
  (block (send nil? #Includes.all ...) ...)
72
72
  (send nil? #Includes.all ...)
@@ -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 = '2.22.0'
7
+ STRING = '2.27.1'
8
8
  end
9
9
  end
10
10
  end
@@ -6,6 +6,8 @@ module RuboCop
6
6
  class Wording
7
7
  SHOULDNT_PREFIX = /\Ashould(?:n't| not)\b/i.freeze
8
8
  SHOULDNT_BE_PREFIX = /#{SHOULDNT_PREFIX} be\b/i.freeze
9
+ WILL_NOT_PREFIX = /\Awill not\b/i.freeze
10
+ WONT_PREFIX = /\Awon't\b/i.freeze
9
11
  ES_SUFFIX_PATTERN = /(?:o|s|x|ch|sh|z)\z/i.freeze
10
12
  IES_SUFFIX_PATTERN = /[^aeou]y\z/i.freeze
11
13
 
@@ -15,16 +17,22 @@ module RuboCop
15
17
  @replacements = replace
16
18
  end
17
19
 
20
+ # rubocop:disable Metrics/MethodLength
18
21
  def rewrite
19
22
  case text
20
23
  when SHOULDNT_BE_PREFIX
21
24
  replace_prefix(SHOULDNT_BE_PREFIX, 'is not')
22
25
  when SHOULDNT_PREFIX
23
26
  replace_prefix(SHOULDNT_PREFIX, 'does not')
27
+ when WILL_NOT_PREFIX
28
+ replace_prefix(WILL_NOT_PREFIX, 'does not')
29
+ when WONT_PREFIX
30
+ replace_prefix(WONT_PREFIX, 'does not')
24
31
  else
25
32
  remove_should_and_pluralize
26
33
  end
27
34
  end
35
+ # rubocop:enable Metrics/MethodLength
28
36
 
29
37
  private
30
38
 
data/lib/rubocop-rspec.rb CHANGED
@@ -17,6 +17,7 @@ require_relative 'rubocop/rspec/wording'
17
17
  # Dependent on `RuboCop::RSpec::Language::NodePattern`.
18
18
  require_relative 'rubocop/rspec/language'
19
19
 
20
+ require_relative 'rubocop/cop/rspec/mixin/file_help'
20
21
  require_relative 'rubocop/cop/rspec/mixin/final_end_location'
21
22
  require_relative 'rubocop/cop/rspec/mixin/inside_example_group'
22
23
  require_relative 'rubocop/cop/rspec/mixin/location_help'
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.22.0
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: 2023-05-06 00:00:00.000000000 Z
13
+ date: 2024-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '1.33'
21
+ version: '1.40'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '1.33'
28
+ version: '1.40'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rubocop-capybara
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -54,9 +54,9 @@ dependencies:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '2.22'
57
- description: |2
58
- Code style checking for RSpec files.
59
- A plugin for the RuboCop code style enforcing & linting tool.
57
+ description: |
58
+ Code style checking for RSpec files.
59
+ A plugin for the RuboCop code style enforcing & linting tool.
60
60
  email:
61
61
  - johncbackus@gmail.com
62
62
  - ian@nevir.net
@@ -112,6 +112,8 @@ files:
112
112
  - lib/rubocop/cop/rspec/empty_line_after_final_let.rb
113
113
  - lib/rubocop/cop/rspec/empty_line_after_hook.rb
114
114
  - lib/rubocop/cop/rspec/empty_line_after_subject.rb
115
+ - lib/rubocop/cop/rspec/empty_metadata.rb
116
+ - lib/rubocop/cop/rspec/eq.rb
115
117
  - lib/rubocop/cop/rspec/example_length.rb
116
118
  - lib/rubocop/cop/rspec/example_without_description.rb
117
119
  - lib/rubocop/cop/rspec/example_wording.rb
@@ -137,6 +139,7 @@ files:
137
139
  - lib/rubocop/cop/rspec/indexed_let.rb
138
140
  - lib/rubocop/cop/rspec/instance_spy.rb
139
141
  - lib/rubocop/cop/rspec/instance_variable.rb
142
+ - lib/rubocop/cop/rspec/is_expected_specify.rb
140
143
  - lib/rubocop/cop/rspec/it_behaves_like.rb
141
144
  - lib/rubocop/cop/rspec/iterated_expectation.rb
142
145
  - lib/rubocop/cop/rspec/leading_subject.rb
@@ -147,9 +150,11 @@ files:
147
150
  - lib/rubocop/cop/rspec/message_chain.rb
148
151
  - lib/rubocop/cop/rspec/message_expectation.rb
149
152
  - lib/rubocop/cop/rspec/message_spies.rb
153
+ - lib/rubocop/cop/rspec/metadata_style.rb
150
154
  - lib/rubocop/cop/rspec/missing_example_group_argument.rb
151
155
  - lib/rubocop/cop/rspec/mixin/comments_help.rb
152
156
  - lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
157
+ - lib/rubocop/cop/rspec/mixin/file_help.rb
153
158
  - lib/rubocop/cop/rspec/mixin/final_end_location.rb
154
159
  - lib/rubocop/cop/rspec/mixin/inside_example_group.rb
155
160
  - lib/rubocop/cop/rspec/mixin/location_help.rb
@@ -175,15 +180,20 @@ files:
175
180
  - lib/rubocop/cop/rspec/rails/http_status.rb
176
181
  - lib/rubocop/cop/rspec/rails/inferred_spec_type.rb
177
182
  - lib/rubocop/cop/rspec/rails/minitest_assertions.rb
183
+ - lib/rubocop/cop/rspec/rails/negation_be_valid.rb
178
184
  - lib/rubocop/cop/rspec/rails/travel_around.rb
179
185
  - lib/rubocop/cop/rspec/receive_counts.rb
186
+ - lib/rubocop/cop/rspec/receive_messages.rb
180
187
  - lib/rubocop/cop/rspec/receive_never.rb
181
188
  - lib/rubocop/cop/rspec/redundant_around.rb
189
+ - lib/rubocop/cop/rspec/redundant_predicate_matcher.rb
190
+ - lib/rubocop/cop/rspec/remove_const.rb
182
191
  - lib/rubocop/cop/rspec/repeated_description.rb
183
192
  - lib/rubocop/cop/rspec/repeated_example.rb
184
193
  - lib/rubocop/cop/rspec/repeated_example_group_body.rb
185
194
  - lib/rubocop/cop/rspec/repeated_example_group_description.rb
186
195
  - lib/rubocop/cop/rspec/repeated_include_example.rb
196
+ - lib/rubocop/cop/rspec/repeated_subject_call.rb
187
197
  - lib/rubocop/cop/rspec/return_from_stub.rb
188
198
  - lib/rubocop/cop/rspec/scattered_let.rb
189
199
  - lib/rubocop/cop/rspec/scattered_setup.rb
@@ -192,6 +202,8 @@ files:
192
202
  - lib/rubocop/cop/rspec/single_argument_message_chain.rb
193
203
  - lib/rubocop/cop/rspec/skip_block_inside_example.rb
194
204
  - lib/rubocop/cop/rspec/sort_metadata.rb
205
+ - lib/rubocop/cop/rspec/spec_file_path_format.rb
206
+ - lib/rubocop/cop/rspec/spec_file_path_suffix.rb
195
207
  - lib/rubocop/cop/rspec/stubbed_mock.rb
196
208
  - lib/rubocop/cop/rspec/subject_declaration.rb
197
209
  - lib/rubocop/cop/rspec/subject_stub.rb
@@ -241,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
253
  - !ruby/object:Gem::Version
242
254
  version: '0'
243
255
  requirements: []
244
- rubygems_version: 3.4.12
256
+ rubygems_version: 3.4.21
245
257
  signing_key:
246
258
  specification_version: 4
247
259
  summary: Code style checking for RSpec files