rubocop-rspec 2.25.0 → 2.26.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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/config/default.yml +19 -2
  4. data/lib/rubocop/cop/rspec/around_block.rb +3 -3
  5. data/lib/rubocop/cop/rspec/be.rb +1 -1
  6. data/lib/rubocop/cop/rspec/be_eq.rb +1 -1
  7. data/lib/rubocop/cop/rspec/be_eql.rb +1 -1
  8. data/lib/rubocop/cop/rspec/be_nil.rb +2 -2
  9. data/lib/rubocop/cop/rspec/before_after_all.rb +7 -13
  10. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +2 -2
  11. data/lib/rubocop/cop/rspec/change_by_zero.rb +3 -3
  12. data/lib/rubocop/cop/rspec/context_method.rb +2 -2
  13. data/lib/rubocop/cop/rspec/context_wording.rb +1 -1
  14. data/lib/rubocop/cop/rspec/describe_symbol.rb +1 -1
  15. data/lib/rubocop/cop/rspec/described_class.rb +5 -5
  16. data/lib/rubocop/cop/rspec/empty_example_group.rb +2 -2
  17. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +2 -2
  18. data/lib/rubocop/cop/rspec/example_wording.rb +11 -2
  19. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +1 -1
  20. data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
  21. data/lib/rubocop/cop/rspec/focus.rb +2 -2
  22. data/lib/rubocop/cop/rspec/hook_argument.rb +2 -2
  23. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -1
  24. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +2 -2
  25. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
  26. data/lib/rubocop/cop/rspec/implicit_subject.rb +2 -2
  27. data/lib/rubocop/cop/rspec/instance_spy.rb +2 -2
  28. data/lib/rubocop/cop/rspec/instance_variable.rb +2 -2
  29. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -3
  30. data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -1
  31. data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
  32. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  33. data/lib/rubocop/cop/rspec/mixin/skip_or_pending.rb +2 -2
  34. data/lib/rubocop/cop/rspec/multiple_expectations.rb +2 -2
  35. data/lib/rubocop/cop/rspec/pending.rb +1 -1
  36. data/lib/rubocop/cop/rspec/pending_without_reason.rb +1 -1
  37. data/lib/rubocop/cop/rspec/predicate_matcher.rb +6 -6
  38. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +1 -1
  39. data/lib/rubocop/cop/rspec/rails/have_http_status.rb +1 -1
  40. data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -1
  41. data/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +2 -2
  42. data/lib/rubocop/cop/rspec/receive_counts.rb +1 -1
  43. data/lib/rubocop/cop/rspec/receive_messages.rb +1 -1
  44. data/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb +65 -0
  45. data/lib/rubocop/cop/rspec/remove_const.rb +40 -0
  46. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +1 -1
  47. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +2 -2
  48. data/lib/rubocop/cop/rspec/repeated_include_example.rb +1 -1
  49. data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -1
  50. data/lib/rubocop/cop/rspec/shared_context.rb +1 -1
  51. data/lib/rubocop/cop/rspec/shared_examples.rb +63 -16
  52. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +1 -1
  53. data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -1
  54. data/lib/rubocop/cop/rspec/subject_stub.rb +4 -4
  55. data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -2
  56. data/lib/rubocop/cop/rspec/variable_definition.rb +2 -2
  57. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -1
  58. data/lib/rubocop/cop/rspec/void_expect.rb +2 -2
  59. data/lib/rubocop/cop/rspec_cops.rb +2 -0
  60. data/lib/rubocop/rspec/language.rb +8 -8
  61. data/lib/rubocop/rspec/version.rb +1 -1
  62. data/lib/rubocop/rspec/wording.rb +8 -0
  63. metadata +8 -6
@@ -70,7 +70,7 @@ module RuboCop
70
70
  TRUE = ->(node) { node.true_type? }
71
71
 
72
72
  # @!method aggregate_failures?(node)
73
- def_node_matcher :aggregate_failures?, <<-PATTERN
73
+ def_node_matcher :aggregate_failures?, <<~PATTERN
74
74
  (block {
75
75
  (send _ _ <(sym :aggregate_failures) ...>)
76
76
  (send _ _ ... (hash <(pair (sym :aggregate_failures) %1) ...>))
@@ -81,7 +81,7 @@ module RuboCop
81
81
  def_node_matcher :expect?, '(send nil? #Expectations.all ...)'
82
82
 
83
83
  # @!method aggregate_failures_block?(node)
84
- def_node_matcher :aggregate_failures_block?, <<-PATTERN
84
+ def_node_matcher :aggregate_failures_block?, <<~PATTERN
85
85
  (block (send nil? :aggregate_failures ...) ...)
86
86
  PATTERN
87
87
 
@@ -67,7 +67,7 @@ module RuboCop
67
67
  private
68
68
 
69
69
  def skipped?(node)
70
- skippable?(node) && skipped_in_metadata?(node) ||
70
+ (skippable?(node) && skipped_in_metadata?(node)) ||
71
71
  skipped_regular_example_without_body?(node)
72
72
  end
73
73
 
@@ -103,7 +103,7 @@ module RuboCop
103
103
  on_pending_by_metadata(node)
104
104
  return unless (parent = parent_node(node))
105
105
 
106
- if example_group?(parent) || block_node_example_group?(node)
106
+ if spec_group?(parent) || block_node_example_group?(node)
107
107
  on_skipped_by_example_method(node)
108
108
  on_skipped_by_example_group_method(node)
109
109
  elsif example?(parent)
@@ -26,7 +26,7 @@ module RuboCop
26
26
  end
27
27
 
28
28
  # @!method predicate_in_actual?(node)
29
- def_node_matcher :predicate_in_actual?, <<-PATTERN
29
+ def_node_matcher :predicate_in_actual?, <<~PATTERN
30
30
  (send
31
31
  (send nil? :expect {
32
32
  (block $(send !nil? #predicate? ...) ...)
@@ -36,12 +36,12 @@ module RuboCop
36
36
  PATTERN
37
37
 
38
38
  # @!method be_bool?(node)
39
- def_node_matcher :be_bool?, <<-PATTERN
39
+ def_node_matcher :be_bool?, <<~PATTERN
40
40
  (send nil? {:be :eq :eql :equal} {true false})
41
41
  PATTERN
42
42
 
43
43
  # @!method be_boolthy?(node)
44
- def_node_matcher :be_boolthy?, <<-PATTERN
44
+ def_node_matcher :be_boolthy?, <<~PATTERN
45
45
  (send nil? {:be_truthy :be_falsey :be_falsy :a_truthy_value :a_falsey_value :a_falsy_value})
46
46
  PATTERN
47
47
 
@@ -179,7 +179,7 @@ module RuboCop
179
179
  end
180
180
 
181
181
  # @!method predicate_matcher?(node)
182
- def_node_matcher :predicate_matcher?, <<-PATTERN
182
+ def_node_matcher :predicate_matcher?, <<~PATTERN
183
183
  (send
184
184
  (send nil? :expect $!nil?)
185
185
  #Runners.all
@@ -188,7 +188,7 @@ module RuboCop
188
188
  PATTERN
189
189
 
190
190
  # @!method predicate_matcher_block?(node)
191
- def_node_matcher :predicate_matcher_block?, <<-PATTERN
191
+ def_node_matcher :predicate_matcher_block?, <<~PATTERN
192
192
  (block
193
193
  (send
194
194
  (send nil? :expect $!nil?)
@@ -202,7 +202,7 @@ module RuboCop
202
202
 
203
203
  return false if allowed_explicit_matchers.include?(name)
204
204
 
205
- name.start_with?('be_', 'have_') && !name.end_with?('?') ||
205
+ (name.start_with?('be_', 'have_') && !name.end_with?('?')) ||
206
206
  %w[include respond_to].include?(name)
207
207
  end
208
208
 
@@ -23,7 +23,7 @@ module RuboCop
23
23
  MSG = 'Use `before` instead of `setup`.'
24
24
 
25
25
  # @!method setup_call(node)
26
- def_node_matcher :setup_call, <<-PATTERN
26
+ def_node_matcher :setup_call, <<~PATTERN
27
27
  (block
28
28
  $(send nil? :setup)
29
29
  (args) _)
@@ -25,7 +25,7 @@ module RuboCop
25
25
  RESTRICT_ON_SEND = RUNNERS
26
26
 
27
27
  # @!method match_status(node)
28
- def_node_matcher :match_status, <<-PATTERN
28
+ def_node_matcher :match_status, <<~PATTERN
29
29
  (send
30
30
  (send nil? :expect
31
31
  $(send (send nil? :response) {:status :code})
@@ -60,7 +60,7 @@ module RuboCop
60
60
  RESTRICT_ON_SEND = %i[have_http_status].freeze
61
61
 
62
62
  # @!method http_status(node)
63
- def_node_matcher :http_status, <<-PATTERN
63
+ def_node_matcher :http_status, <<~PATTERN
64
64
  (send nil? :have_http_status ${int sym str})
65
65
  PATTERN
66
66
 
@@ -24,8 +24,8 @@ module RuboCop
24
24
  RESTRICT_ON_SEND = %i[assert_equal refute_equal].freeze
25
25
 
26
26
  # @!method minitest_assertion(node)
27
- def_node_matcher :minitest_assertion, <<-PATTERN
28
- (send nil? {:assert_equal :refute_equal} $_ $_ $_?)
27
+ def_node_matcher :minitest_assertion, <<~PATTERN
28
+ (send nil? {:assert_equal :refute_equal} $_ $_ $_?)
29
29
  PATTERN
30
30
 
31
31
  def on_send(node)
@@ -30,7 +30,7 @@ module RuboCop
30
30
  RESTRICT_ON_SEND = %i[times].freeze
31
31
 
32
32
  # @!method receive_counts(node)
33
- def_node_matcher :receive_counts, <<-PATTERN
33
+ def_node_matcher :receive_counts, <<~PATTERN
34
34
  (send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times)
35
35
  PATTERN
36
36
 
@@ -148,7 +148,7 @@ module RuboCop
148
148
  end
149
149
 
150
150
  def heredoc_or_splat?(node)
151
- (node.str_type? || node.dstr_type?) && node.heredoc? ||
151
+ ((node.str_type? || node.dstr_type?) && node.heredoc?) ||
152
152
  node.splat_type?
153
153
  end
154
154
 
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Checks for redundant predicate matcher.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # expect(foo).to be_exist(bar)
11
+ # expect(foo).not_to be_include(bar)
12
+ #
13
+ # # good
14
+ # expect(foo).to exist(bar)
15
+ # expect(foo).not_to include(bar)
16
+ #
17
+ class RedundantPredicateMatcher < Base
18
+ extend AutoCorrector
19
+
20
+ MSG = 'Use `%<good>s` instead of `%<bad>s`.'
21
+ RESTRICT_ON_SEND =
22
+ %i[be_all be_cover be_end_with be_eql be_equal
23
+ be_exist be_exists be_include be_match
24
+ be_respond_to be_start_with].freeze
25
+
26
+ def on_send(node)
27
+ return if node.parent.block_type? || node.arguments.empty?
28
+ return unless replacable_arguments?(node)
29
+
30
+ method_name = node.method_name.to_s
31
+ replaced = replaced_method_name(method_name)
32
+ add_offense(node, message: message(method_name,
33
+ replaced)) do |corrector|
34
+ unless node.method?(:be_all)
35
+ corrector.replace(node.loc.selector, replaced)
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def message(bad_method, good_method)
43
+ format(MSG, bad: bad_method, good: good_method)
44
+ end
45
+
46
+ def replacable_arguments?(node)
47
+ if node.method?(:be_all)
48
+ node.first_argument.send_type?
49
+ else
50
+ true
51
+ end
52
+ end
53
+
54
+ def replaced_method_name(method_name)
55
+ name = method_name.to_s.delete_prefix('be_')
56
+ if name == 'exists'
57
+ 'exist'
58
+ else
59
+ name
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Checks that `remove_const` is not used in specs.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # it 'does something' do
11
+ # Object.send(:remove_const, :SomeConstant)
12
+ # end
13
+ #
14
+ # before do
15
+ # SomeClass.send(:remove_const, :SomeConstant)
16
+ # end
17
+ #
18
+ class RemoveConst < Base
19
+ include RuboCop::RSpec::Language
20
+ extend RuboCop::RSpec::Language::NodePattern
21
+
22
+ MSG = 'Do not use remove_const in specs. ' \
23
+ 'Consider using e.g. `stub_const`.'
24
+ RESTRICT_ON_SEND = %i[send __send__].freeze
25
+
26
+ # @!method remove_const(node)
27
+ def_node_matcher :remove_const, <<~PATTERN
28
+ (send _ {:send | :__send__} (sym :remove_const) _)
29
+ PATTERN
30
+
31
+ # Check for offenses
32
+ def on_send(node)
33
+ remove_const(node) do
34
+ add_offense(node)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -48,7 +48,7 @@ module RuboCop
48
48
  MSG = 'Repeated %<group>s block body on line(s) %<loc>s'
49
49
 
50
50
  # @!method several_example_groups?(node)
51
- def_node_matcher :several_example_groups?, <<-PATTERN
51
+ def_node_matcher :several_example_groups?, <<~PATTERN
52
52
  (begin <#example_group_with_body? #example_group_with_body? ...>)
53
53
  PATTERN
54
54
 
@@ -48,12 +48,12 @@ module RuboCop
48
48
  MSG = 'Repeated %<group>s block description on line(s) %<loc>s'
49
49
 
50
50
  # @!method several_example_groups?(node)
51
- def_node_matcher :several_example_groups?, <<-PATTERN
51
+ def_node_matcher :several_example_groups?, <<~PATTERN
52
52
  (begin <#example_group? #example_group? ...>)
53
53
  PATTERN
54
54
 
55
55
  # @!method doc_string_and_metadata(node)
56
- def_node_matcher :doc_string_and_metadata, <<-PATTERN
56
+ def_node_matcher :doc_string_and_metadata, <<~PATTERN
57
57
  (block (send _ _ $_ $...) ...)
58
58
  PATTERN
59
59
 
@@ -50,7 +50,7 @@ module RuboCop
50
50
  'on line(s) %<repeat>s'
51
51
 
52
52
  # @!method several_include_examples?(node)
53
- def_node_matcher :several_include_examples?, <<-PATTERN
53
+ def_node_matcher :several_include_examples?, <<~PATTERN
54
54
  (begin <#include_examples? #include_examples? ...>)
55
55
  PATTERN
56
56
 
@@ -48,7 +48,7 @@ module RuboCop
48
48
  def_node_matcher :stub_with_block?, '(block #contains_stub? ...)'
49
49
 
50
50
  # @!method and_return_value(node)
51
- def_node_search :and_return_value, <<-PATTERN
51
+ def_node_search :and_return_value, <<~PATTERN
52
52
  $(send _ :and_return $(...))
53
53
  PATTERN
54
54
 
@@ -62,7 +62,7 @@ module RuboCop
62
62
  PATTERN
63
63
 
64
64
  # @!method context?(node)
65
- def_node_search :context?, <<-PATTERN
65
+ def_node_search :context?, <<~PATTERN
66
66
  (send nil?
67
67
  {#Subjects.all #Helpers.all #Includes.context #Hooks.all} ...
68
68
  )
@@ -3,9 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- # Enforces use of string to titleize shared examples.
6
+ # Checks for consistent style for shared example names.
7
7
  #
8
- # @example
8
+ # Enforces either `string` or `symbol` for shared example names.
9
+ #
10
+ # This cop can be configured using the `EnforcedStyle` option
11
+ #
12
+ # @example `EnforcedStyle: string` (default)
9
13
  # # bad
10
14
  # it_behaves_like :foo_bar_baz
11
15
  # it_should_behave_like :foo_bar_baz
@@ -20,8 +24,24 @@ module RuboCop
20
24
  # shared_examples_for 'foo bar baz'
21
25
  # include_examples 'foo bar baz'
22
26
  #
27
+ # @example `EnforcedStyle: symbol`
28
+ # # bad
29
+ # it_behaves_like 'foo bar baz'
30
+ # it_should_behave_like 'foo bar baz'
31
+ # shared_examples 'foo bar baz'
32
+ # shared_examples_for 'foo bar baz'
33
+ # include_examples 'foo bar baz'
34
+ #
35
+ # # good
36
+ # it_behaves_like :foo_bar_baz
37
+ # it_should_behave_like :foo_bar_baz
38
+ # shared_examples :foo_bar_baz
39
+ # shared_examples_for :foo_bar_baz
40
+ # include_examples :foo_bar_baz
41
+ #
23
42
  class SharedExamples < Base
24
43
  extend AutoCorrector
44
+ include ConfigurableEnforcedStyle
25
45
 
26
46
  # @!method shared_examples(node)
27
47
  def_node_matcher :shared_examples, <<~PATTERN
@@ -34,19 +54,37 @@ module RuboCop
34
54
  def on_send(node)
35
55
  shared_examples(node) do
36
56
  ast_node = node.first_argument
37
- next unless ast_node&.sym_type?
57
+ next unless offense?(ast_node)
38
58
 
39
- checker = Checker.new(ast_node)
40
- add_offense(checker.node, message: checker.message) do |corrector|
41
- corrector.replace(checker.node, checker.preferred_style)
59
+ checker = new_checker(ast_node)
60
+ add_offense(ast_node, message: checker.message) do |corrector|
61
+ corrector.replace(ast_node, checker.preferred_style)
42
62
  end
43
63
  end
44
64
  end
45
65
 
66
+ private
67
+
68
+ def offense?(ast_node)
69
+ if style == :symbol
70
+ ast_node.str_type?
71
+ else # string
72
+ ast_node.sym_type?
73
+ end
74
+ end
75
+
76
+ def new_checker(ast_node)
77
+ if style == :symbol
78
+ SymbolChecker.new(ast_node)
79
+ else # string
80
+ StringChecker.new(ast_node)
81
+ end
82
+ end
83
+
46
84
  # :nodoc:
47
- class Checker
85
+ class SymbolChecker
48
86
  MSG = 'Prefer %<prefer>s over `%<current>s` ' \
49
- 'to titleize shared examples.'
87
+ 'to symbolize shared examples.'
50
88
 
51
89
  attr_reader :node
52
90
 
@@ -55,22 +93,31 @@ module RuboCop
55
93
  end
56
94
 
57
95
  def message
58
- format(MSG, prefer: preferred_style, current: symbol.inspect)
96
+ format(MSG, prefer: preferred_style, current: node.value.inspect)
59
97
  end
60
98
 
61
99
  def preferred_style
62
- string = symbol.to_s.tr('_', ' ')
63
- wrap_with_single_quotes(string)
100
+ ":#{node.value.to_s.downcase.tr(' ', '_')}"
64
101
  end
102
+ end
103
+
104
+ # :nodoc:
105
+ class StringChecker
106
+ MSG = 'Prefer %<prefer>s over `%<current>s` ' \
107
+ 'to titleize shared examples.'
65
108
 
66
- private
109
+ attr_reader :node
67
110
 
68
- def symbol
69
- node.value
111
+ def initialize(node)
112
+ @node = node
70
113
  end
71
114
 
72
- def wrap_with_single_quotes(string)
73
- "'#{string}'"
115
+ def message
116
+ format(MSG, prefer: preferred_style, current: node.value.inspect)
117
+ end
118
+
119
+ def preferred_style
120
+ "'#{node.value.to_s.tr('_', ' ')}'"
74
121
  end
75
122
  end
76
123
  end
@@ -24,7 +24,7 @@ module RuboCop
24
24
  RESTRICT_ON_SEND = %i[receive_message_chain stub_chain].freeze
25
25
 
26
26
  # @!method message_chain(node)
27
- def_node_matcher :message_chain, <<-PATTERN
27
+ def_node_matcher :message_chain, <<~PATTERN
28
28
  (send _ {:receive_message_chain :stub_chain} $_)
29
29
  PATTERN
30
30
 
@@ -31,7 +31,7 @@ module RuboCop
31
31
  #
32
32
  # @param node [RuboCop::AST::Node]
33
33
  # @return [Array<RuboCop::AST::Node>] matching nodes
34
- def_node_matcher :message_expectation?, <<-PATTERN
34
+ def_node_matcher :message_expectation?, <<~PATTERN
35
35
  {
36
36
  (send nil? { :receive :receive_message_chain } ...) # receive(:foo)
37
37
  (send (send nil? :receive ...) :with ...) # receive(:foo).with('bar')
@@ -68,7 +68,7 @@ module RuboCop
68
68
  # @param node [RuboCop::AST::Node]
69
69
  #
70
70
  # @yield [Symbol] subject name
71
- def_node_matcher :subject?, <<-PATTERN
71
+ def_node_matcher :subject?, <<~PATTERN
72
72
  (block
73
73
  (send nil?
74
74
  { #Subjects.all (sym $_) | $#Subjects.all }
@@ -77,7 +77,7 @@ module RuboCop
77
77
 
78
78
  # @!method let?(node)
79
79
  # Find a memoized helper
80
- def_node_matcher :let?, <<-PATTERN
80
+ def_node_matcher :let?, <<~PATTERN
81
81
  (block
82
82
  (send nil? :let (sym $_)
83
83
  ) args ...)
@@ -94,7 +94,7 @@ module RuboCop
94
94
  # expect(foo).to receive(:bar).with(1)
95
95
  # expect(foo).to receive(:bar).with(1).and_return(2)
96
96
  #
97
- def_node_matcher :message_expectation?, <<-PATTERN
97
+ def_node_matcher :message_expectation?, <<~PATTERN
98
98
  (send
99
99
  {
100
100
  (send nil? { :expect :allow } (send nil? %))
@@ -106,7 +106,7 @@ module RuboCop
106
106
  PATTERN
107
107
 
108
108
  # @!method message_expectation_matcher?(node)
109
- def_node_search :message_expectation_matcher?, <<-PATTERN
109
+ def_node_search :message_expectation_matcher?, <<~PATTERN
110
110
  (send nil? {
111
111
  :receive :receive_messages :receive_message_chain :have_received
112
112
  } ...)
@@ -35,7 +35,7 @@ module RuboCop
35
35
  RESTRICT_ON_SEND = %i[to].freeze
36
36
 
37
37
  # @!method empty_raise_error_or_exception(node)
38
- def_node_matcher :empty_raise_error_or_exception, <<-PATTERN
38
+ def_node_matcher :empty_raise_error_or_exception, <<~PATTERN
39
39
  (send
40
40
  (block
41
41
  (send nil? :expect) ...)
@@ -57,7 +57,7 @@ module RuboCop
57
57
  end
58
58
 
59
59
  def block_with_args?(node)
60
- return unless node&.block_type?
60
+ return false unless node&.block_type?
61
61
 
62
62
  node.arguments?
63
63
  end
@@ -60,8 +60,8 @@ module RuboCop
60
60
  end
61
61
 
62
62
  def style_offense?(variable)
63
- style == :symbols && string?(variable) ||
64
- style == :strings && symbol?(variable)
63
+ (style == :symbols && string?(variable)) ||
64
+ (style == :strings && symbol?(variable))
65
65
  end
66
66
 
67
67
  def string?(node)
@@ -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
 
@@ -106,6 +106,8 @@ require_relative 'rspec/receive_counts'
106
106
  require_relative 'rspec/receive_messages'
107
107
  require_relative 'rspec/receive_never'
108
108
  require_relative 'rspec/redundant_around'
109
+ require_relative 'rspec/redundant_predicate_matcher'
110
+ require_relative 'rspec/remove_const'
109
111
  require_relative 'rspec/repeated_description'
110
112
  require_relative 'rspec/repeated_example'
111
113
  require_relative 'rspec/repeated_example_group_body'
@@ -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.25.0'
7
+ STRING = '2.26.0'
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