rubocop-rspec 1.38.0 → 1.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/CODE_OF_CONDUCT.md +17 -0
  4. data/README.md +1 -61
  5. data/config/default.yml +147 -17
  6. data/lib/rubocop-rspec.rb +3 -1
  7. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +11 -18
  8. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +11 -18
  9. data/lib/rubocop/cop/rspec/be.rb +1 -1
  10. data/lib/rubocop/cop/rspec/be_eql.rb +5 -5
  11. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +18 -16
  12. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +8 -9
  13. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +69 -0
  14. data/lib/rubocop/cop/rspec/context_method.rb +5 -7
  15. data/lib/rubocop/cop/rspec/cop.rb +9 -29
  16. data/lib/rubocop/cop/rspec/describe_class.rb +20 -5
  17. data/lib/rubocop/cop/rspec/describe_method.rb +0 -1
  18. data/lib/rubocop/cop/rspec/described_class.rb +10 -7
  19. data/lib/rubocop/cop/rspec/dialect.rb +4 -11
  20. data/lib/rubocop/cop/rspec/empty_hook.rb +46 -0
  21. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +5 -3
  22. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +5 -5
  23. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +4 -1
  24. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +5 -5
  25. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +4 -1
  26. data/lib/rubocop/cop/rspec/example_wording.rb +6 -7
  27. data/lib/rubocop/cop/rspec/expect_actual.rb +7 -10
  28. data/lib/rubocop/cop/rspec/expect_change.rb +9 -34
  29. data/lib/rubocop/cop/rspec/expect_in_hook.rb +2 -2
  30. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  31. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +23 -20
  32. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +10 -16
  33. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +6 -7
  34. data/lib/rubocop/cop/rspec/file_path.rb +32 -4
  35. data/lib/rubocop/cop/rspec/hook_argument.rb +11 -17
  36. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +9 -28
  37. data/lib/rubocop/cop/rspec/implicit_expect.rb +6 -14
  38. data/lib/rubocop/cop/rspec/implicit_subject.rb +8 -5
  39. data/lib/rubocop/cop/rspec/instance_spy.rb +17 -11
  40. data/lib/rubocop/cop/rspec/instance_variable.rb +3 -7
  41. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +2 -5
  42. data/lib/rubocop/cop/rspec/it_behaves_like.rb +4 -5
  43. data/lib/rubocop/cop/rspec/leading_subject.rb +12 -19
  44. data/lib/rubocop/cop/rspec/leaky_constant_declaration.rb +1 -4
  45. data/lib/rubocop/cop/rspec/let_before_examples.rb +9 -25
  46. data/lib/rubocop/cop/rspec/let_setup.rb +15 -3
  47. data/lib/rubocop/cop/rspec/message_chain.rb +6 -5
  48. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  49. data/lib/rubocop/cop/rspec/message_spies.rb +1 -2
  50. data/lib/rubocop/cop/rspec/multiple_subjects.rb +17 -18
  51. data/lib/rubocop/cop/rspec/named_subject.rb +7 -7
  52. data/lib/rubocop/cop/rspec/nested_groups.rb +9 -10
  53. data/lib/rubocop/cop/rspec/not_to_not.rb +4 -5
  54. data/lib/rubocop/cop/rspec/predicate_matcher.rb +25 -55
  55. data/lib/rubocop/cop/rspec/rails/http_status.rb +6 -8
  56. data/lib/rubocop/cop/rspec/receive_counts.rb +14 -16
  57. data/lib/rubocop/cop/rspec/receive_never.rb +10 -10
  58. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +11 -1
  59. data/lib/rubocop/cop/rspec/return_from_stub.rb +11 -21
  60. data/lib/rubocop/cop/rspec/scattered_let.rb +11 -1
  61. data/lib/rubocop/cop/rspec/shared_context.rb +7 -20
  62. data/lib/rubocop/cop/rspec/shared_examples.rb +6 -8
  63. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +14 -17
  64. data/lib/rubocop/cop/rspec/subject_stub.rb +23 -51
  65. data/lib/rubocop/cop/rspec/variable_definition.rb +56 -0
  66. data/lib/rubocop/cop/rspec/variable_name.rb +47 -0
  67. data/lib/rubocop/cop/rspec/yield.rb +13 -10
  68. data/lib/rubocop/cop/rspec_cops.rb +5 -1
  69. data/lib/rubocop/rspec/blank_line_separation.rb +0 -8
  70. data/lib/rubocop/rspec/corrector/move_node.rb +52 -0
  71. data/lib/rubocop/rspec/description_extractor.rb +2 -6
  72. data/lib/rubocop/rspec/example.rb +1 -1
  73. data/lib/rubocop/rspec/example_group.rb +21 -49
  74. data/lib/rubocop/rspec/factory_bot.rb +7 -1
  75. data/lib/rubocop/rspec/language.rb +8 -0
  76. data/lib/rubocop/rspec/language/node_pattern.rb +5 -1
  77. data/lib/rubocop/rspec/top_level_group.rb +44 -0
  78. data/lib/rubocop/rspec/variable.rb +16 -0
  79. data/lib/rubocop/rspec/version.rb +1 -1
  80. metadata +17 -10
  81. data/lib/rubocop/rspec/util.rb +0 -19
@@ -32,7 +32,7 @@ module RuboCop
32
32
  # it { expect_something_else }
33
33
  #
34
34
  class LeadingSubject < Cop
35
- include RangeHelp
35
+ extend AutoCorrector
36
36
 
37
37
  MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
38
38
 
@@ -45,28 +45,25 @@ module RuboCop
45
45
  def check_previous_nodes(node)
46
46
  node.parent.each_child_node do |sibling|
47
47
  if offending?(sibling)
48
- add_offense(
49
- node,
50
- message: format(MSG, offending: sibling.method_name)
51
- )
48
+ msg = format(MSG, offending: sibling.method_name)
49
+ add_offense(node, message: msg) do |corrector|
50
+ autocorrect(corrector, node)
51
+ end
52
52
  end
53
53
 
54
54
  break if offending?(sibling) || sibling.equal?(node)
55
55
  end
56
56
  end
57
57
 
58
- def autocorrect(node)
59
- lambda do |corrector|
60
- first_node = find_first_offending_node(node)
61
- first_node_position = first_node.loc.expression
62
- indent = "\n" + ' ' * first_node.loc.column
63
- corrector.insert_before(first_node_position, node.source + indent)
64
- corrector.remove(node_range(node))
65
- end
66
- end
67
-
68
58
  private
69
59
 
60
+ def autocorrect(corrector, node)
61
+ first_node = find_first_offending_node(node)
62
+ RuboCop::RSpec::Corrector::MoveNode.new(
63
+ node, corrector, processed_source
64
+ ).move_before(first_node)
65
+ end
66
+
70
67
  def offending?(node)
71
68
  let?(node) || hook?(node) || example?(node)
72
69
  end
@@ -75,10 +72,6 @@ module RuboCop
75
72
  node.parent.children.find { |sibling| offending?(sibling) }
76
73
  end
77
74
 
78
- def node_range(node)
79
- range_by_whole_lines(node.source_range, include_final_newline: true)
80
- end
81
-
82
75
  def in_spec_block?(node)
83
76
  node.each_ancestor(:block).any? do |ancestor|
84
77
  example?(ancestor)
@@ -119,11 +119,8 @@ module RuboCop
119
119
  private
120
120
 
121
121
  def inside_describe_block?(node)
122
- node.each_ancestor(:block).any?(&method(:in_example_or_shared_group?))
122
+ node.each_ancestor(:block).any?(&method(:spec_group?))
123
123
  end
124
-
125
- def_node_matcher :in_example_or_shared_group?,
126
- (ExampleGroups::ALL + SharedGroups::ALL).block_pattern
127
124
  end
128
125
  end
129
126
  end
@@ -31,8 +31,7 @@ module RuboCop
31
31
  # expect(some).to be
32
32
  # end
33
33
  class LetBeforeExamples < Cop
34
- include RangeHelp
35
- include RuboCop::RSpec::FinalEndLocation
34
+ extend AutoCorrector
36
35
 
37
36
  MSG = 'Move `let` before the examples in the group.'
38
37
 
@@ -49,17 +48,6 @@ module RuboCop
49
48
  check_let_declarations(node.body) if multiline_block?(node.body)
50
49
  end
51
50
 
52
- def autocorrect(node)
53
- lambda do |corrector|
54
- first_example = find_first_example(node.parent)
55
- first_example_pos = first_example.loc.expression
56
- indent = "\n" + ' ' * first_example.loc.column
57
-
58
- corrector.insert_before(first_example_pos, source(node) + indent)
59
- corrector.remove(node_range_with_surrounding_space(node))
60
- end
61
- end
62
-
63
51
  private
64
52
 
65
53
  def multiline_block?(block)
@@ -72,8 +60,11 @@ module RuboCop
72
60
 
73
61
  node.each_child_node do |child|
74
62
  next if child.sibling_index < first_example.sibling_index
63
+ next unless let?(child)
75
64
 
76
- add_offense(child) if let?(child)
65
+ add_offense(child) do |corrector|
66
+ autocorrect(corrector, child, first_example)
67
+ end
77
68
  end
78
69
  end
79
70
 
@@ -81,17 +72,10 @@ module RuboCop
81
72
  node.children.find { |sibling| example_or_group?(sibling) }
82
73
  end
83
74
 
84
- def node_range_with_surrounding_space(node)
85
- range = node_range(node)
86
- range_by_whole_lines(range, include_final_newline: true)
87
- end
88
-
89
- def source(node)
90
- node_range(node).source
91
- end
92
-
93
- def node_range(node)
94
- node.loc.expression.with(end_pos: final_end_location(node).end_pos)
75
+ def autocorrect(corrector, node, first_example)
76
+ RuboCop::RSpec::Corrector::MoveNode.new(
77
+ node, corrector, processed_source
78
+ ).move_before(first_example)
95
79
  end
96
80
  end
97
81
  end
@@ -28,14 +28,20 @@ module RuboCop
28
28
  class LetSetup < Cop
29
29
  MSG = 'Do not use `let!` to setup objects not referenced in tests.'
30
30
 
31
- def_node_search :let_bang, <<-PATTERN
31
+ def_node_matcher :example_or_shared_group_or_including?,
32
+ (
33
+ ExampleGroups::ALL + SharedGroups::ALL +
34
+ Includes::ALL
35
+ ).block_pattern
36
+
37
+ def_node_matcher :let_bang, <<-PATTERN
32
38
  (block $(send nil? :let! (sym $_)) args ...)
33
39
  PATTERN
34
40
 
35
41
  def_node_search :method_called?, '(send nil? %)'
36
42
 
37
43
  def on_block(node)
38
- return unless example_group?(node)
44
+ return unless example_or_shared_group_or_including?(node)
39
45
 
40
46
  unused_let_bang(node) do |let|
41
47
  add_offense(let)
@@ -45,10 +51,16 @@ module RuboCop
45
51
  private
46
52
 
47
53
  def unused_let_bang(node)
48
- let_bang(node) do |method_send, method_name|
54
+ child_let_bang(node) do |method_send, method_name|
49
55
  yield(method_send) unless method_called?(node, method_name)
50
56
  end
51
57
  end
58
+
59
+ def child_let_bang(node, &block)
60
+ RuboCop::RSpec::ExampleGroup.new(node).lets.each do |let|
61
+ let_bang(let, &block)
62
+ end
63
+ end
52
64
  end
53
65
  end
54
66
  end
@@ -21,11 +21,12 @@ module RuboCop
21
21
  PATTERN
22
22
 
23
23
  def on_send(node)
24
- message_chain(node) { add_offense(node, location: :selector) }
25
- end
26
-
27
- def message(node)
28
- format(MSG, method: node.method_name)
24
+ message_chain(node) do
25
+ add_offense(
26
+ node.loc.selector,
27
+ message: format(MSG, method: node.method_name)
28
+ )
29
+ end
29
30
  end
30
31
  end
31
32
  end
@@ -42,7 +42,7 @@ module RuboCop
42
42
  return correct_style_detected if preferred_style?(match)
43
43
 
44
44
  message = format(MSG, style: style)
45
- add_offense(match, location: :selector, message: message) do
45
+ add_offense(match.loc.selector, message: message) do
46
46
  opposite_style_detected
47
47
  end
48
48
  end
@@ -48,8 +48,7 @@ module RuboCop
48
48
  return correct_style_detected if preferred_style?(message_matcher)
49
49
 
50
50
  add_offense(
51
- message_matcher,
52
- location: :selector,
51
+ message_matcher.loc.selector,
53
52
  message: error_message(receiver)
54
53
  ) { opposite_style_detected }
55
54
  end
@@ -34,6 +34,7 @@ module RuboCop
34
34
  # This is enough of an edge case that people can just move this to
35
35
  # a `before` hook on their own
36
36
  class MultipleSubjects < Cop
37
+ extend AutoCorrector
37
38
  include RangeHelp
38
39
 
39
40
  MSG = 'Do not set more than one subject per example group'
@@ -44,38 +45,36 @@ module RuboCop
44
45
  subjects = RuboCop::RSpec::ExampleGroup.new(node).subjects
45
46
 
46
47
  subjects[0...-1].each do |subject|
47
- add_offense(subject)
48
+ add_offense(subject) do |corrector|
49
+ autocorrect(corrector, subject)
50
+ end
48
51
  end
49
52
  end
50
53
 
51
- def autocorrect(node)
52
- return unless node.method_name.equal?(:subject) # Ignore `subject!`
54
+ private
55
+
56
+ def autocorrect(corrector, subject)
57
+ return unless subject.method_name.equal?(:subject) # Ignore `subject!`
53
58
 
54
- if named_subject?(node)
55
- rename_autocorrect(node)
59
+ if named_subject?(subject)
60
+ rename_autocorrect(corrector, subject)
56
61
  else
57
- remove_autocorrect(node)
62
+ remove_autocorrect(corrector, subject)
58
63
  end
59
64
  end
60
65
 
61
- private
62
-
63
66
  def named_subject?(node)
64
67
  node.send_node.arguments?
65
68
  end
66
69
 
67
- def rename_autocorrect(node)
68
- lambda do |corrector|
69
- corrector.replace(node.send_node.loc.selector, 'let')
70
- end
70
+ def rename_autocorrect(corrector, node)
71
+ corrector.replace(node.send_node.loc.selector, 'let')
71
72
  end
72
73
 
73
- def remove_autocorrect(node)
74
- lambda do |corrector|
75
- range = range_by_whole_lines(node.source_range,
76
- include_final_newline: true)
77
- corrector.remove(range)
78
- end
74
+ def remove_autocorrect(corrector, node)
75
+ range = range_by_whole_lines(node.source_range,
76
+ include_final_newline: true)
77
+ corrector.remove(range)
79
78
  end
80
79
  end
81
80
  end
@@ -6,11 +6,11 @@ module RuboCop
6
6
  # Checks for explicitly referenced test subjects.
7
7
  #
8
8
  # RSpec lets you declare an "implicit subject" using `subject { ... }`
9
- # which allows for tests like `it { should be_valid }`. If you need to
10
- # reference your test subject you should explicitly name it using
11
- # `subject(:your_subject_name) { ... }`. Your test subjects should be
12
- # the most important object in your tests so they deserve a descriptive
13
- # name.
9
+ # which allows for tests like `it { is_expected.to be_valid }`.
10
+ # If you need to reference your test subject you should explicitly
11
+ # name it using `subject(:your_subject_name) { ... }`. Your test subjects
12
+ # should be the most important object in your tests so they deserve
13
+ # a descriptive name.
14
14
  #
15
15
  # This cop can be configured in your configuration using the
16
16
  # `IgnoreSharedExamples` which will not report offenses for implicit
@@ -39,7 +39,7 @@ module RuboCop
39
39
  # RSpec.describe Foo do
40
40
  # subject(:user) { described_class.new }
41
41
  #
42
- # it { should be_valid }
42
+ # it { is_expected.to be_valid }
43
43
  # end
44
44
  class NamedSubject < Cop
45
45
  MSG = 'Name your test subject if you need '\
@@ -62,7 +62,7 @@ module RuboCop
62
62
  return if !rspec_block?(node) || ignored_shared_example?(node)
63
63
 
64
64
  subject_usage(node) do |subject_node|
65
- add_offense(subject_node, location: :selector)
65
+ add_offense(subject_node.loc.selector)
66
66
  end
67
67
  end
68
68
 
@@ -97,13 +97,11 @@ module RuboCop
97
97
  "Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
98
98
  'deprecated in favor of `Max`. Please use that instead.'
99
99
 
100
- def_node_search :find_contexts, ExampleGroups::ALL.block_pattern
101
-
102
100
  def on_top_level_describe(node, _args)
103
- find_nested_contexts(node.parent) do |context, nesting|
101
+ find_nested_example_groups(node.parent) do |example_group, nesting|
104
102
  self.max = nesting
105
103
  add_offense(
106
- context.send_node,
104
+ example_group.send_node,
107
105
  message: message(nesting)
108
106
  )
109
107
  end
@@ -111,13 +109,14 @@ module RuboCop
111
109
 
112
110
  private
113
111
 
114
- def find_nested_contexts(node, nesting: 1, &block)
115
- find_contexts(node) do |nested_context|
116
- yield(nested_context, nesting) if nesting > max_nesting
112
+ def find_nested_example_groups(node, nesting: 1, &block)
113
+ example_group = example_group?(node)
114
+ yield node, nesting if example_group && nesting > max_nesting
115
+
116
+ next_nesting = example_group ? nesting + 1 : nesting
117
117
 
118
- nested_context.each_child_node do |child|
119
- find_nested_contexts(child, nesting: nesting + 1, &block)
120
- end
118
+ node.each_child_node(:block, :begin) do |child|
119
+ find_nested_example_groups(child, nesting: next_nesting, &block)
121
120
  end
122
121
  end
123
122
 
@@ -16,6 +16,7 @@ module RuboCop
16
16
  # expect(false).not_to be_true
17
17
  # end
18
18
  class NotToNot < Cop
19
+ extend AutoCorrector
19
20
  include ConfigurableEnforcedStyle
20
21
 
21
22
  MSG = 'Prefer `%<replacement>s` over `%<original>s`.'
@@ -24,14 +25,12 @@ module RuboCop
24
25
 
25
26
  def on_send(node)
26
27
  not_to_not_offense(node, alternative_style) do
27
- add_offense(node, location: :selector)
28
+ add_offense(node.loc.selector) do |corrector|
29
+ corrector.replace(node.loc.selector, style.to_s)
30
+ end
28
31
  end
29
32
  end
30
33
 
31
- def autocorrect(node)
32
- ->(corrector) { corrector.replace(node.loc.selector, style.to_s) }
33
- end
34
-
35
34
  private
36
35
 
37
36
  def message(_node)
@@ -14,11 +14,14 @@ module RuboCop
14
14
  private
15
15
 
16
16
  def check_inflected(node)
17
- predicate_in_actual?(node) do |predicate|
18
- add_offense(
19
- node,
20
- message: message_inflected(predicate)
21
- )
17
+ predicate_in_actual?(node) do |predicate, to, matcher|
18
+ msg = message_inflected(predicate)
19
+ add_offense(node, message: msg) do |corrector|
20
+ remove_predicate(corrector, predicate)
21
+ corrector.replace(node.loc.selector,
22
+ true?(to, matcher) ? 'to' : 'not_to')
23
+ rewrite_matcher(corrector, predicate, matcher)
24
+ end
22
25
  end
23
26
  end
24
27
 
@@ -76,17 +79,6 @@ module RuboCop
76
79
  end
77
80
  # rubocop:enable Metrics/MethodLength
78
81
 
79
- def autocorrect_inflected(node)
80
- predicate_in_actual?(node) do |predicate, to, matcher|
81
- lambda do |corrector|
82
- remove_predicate(corrector, predicate)
83
- corrector.replace(node.loc.selector,
84
- true?(to, matcher) ? 'to' : 'not_to')
85
- rewrite_matcher(corrector, predicate, matcher)
86
- end
87
- end
88
- end
89
-
90
82
  def remove_predicate(corrector, predicate)
91
83
  range = predicate.loc.dot.with(
92
84
  end_pos: predicate.loc.expression.end_pos
@@ -123,7 +115,6 @@ module RuboCop
123
115
  end
124
116
 
125
117
  # A helper for `explicit` style
126
- # rubocop:disable Metrics/ModuleLength
127
118
  module ExplicitHelper
128
119
  include RuboCop::RSpec::Language
129
120
  extend NodePattern::Macros
@@ -143,22 +134,21 @@ module RuboCop
143
134
  end
144
135
 
145
136
  def check_explicit(node) # rubocop:disable Metrics/MethodLength
146
- predicate_matcher_block?(node) do |_actual, matcher|
147
- add_offense(
148
- node,
149
- message: message_explicit(matcher)
150
- )
137
+ predicate_matcher_block?(node) do |actual, matcher|
138
+ add_offense(node, message: message_explicit(matcher)) do |corrector|
139
+ to_node = node.send_node
140
+ corrector_explicit(corrector, to_node, actual, matcher, to_node)
141
+ end
151
142
  ignore_node(node.children.first)
152
143
  return
153
144
  end
154
145
 
155
146
  return if part_of_ignored_node?(node)
156
147
 
157
- predicate_matcher?(node) do |_actual, matcher|
158
- add_offense(
159
- node,
160
- message: message_explicit(matcher)
161
- )
148
+ predicate_matcher?(node) do |actual, matcher|
149
+ add_offense(node, message: message_explicit(matcher)) do |corrector|
150
+ corrector_explicit(corrector, node, actual, matcher, matcher)
151
+ end
162
152
  end
163
153
  end
164
154
 
@@ -193,31 +183,11 @@ module RuboCop
193
183
  matcher_name: matcher.method_name)
194
184
  end
195
185
 
196
- def autocorrect_explicit(node)
197
- autocorrect_explicit_send(node) ||
198
- autocorrect_explicit_block(node)
199
- end
200
-
201
- def autocorrect_explicit_send(node)
202
- predicate_matcher?(node) do |actual, matcher|
203
- corrector_explicit(node, actual, matcher, matcher)
204
- end
205
- end
206
-
207
- def autocorrect_explicit_block(node)
208
- predicate_matcher_block?(node) do |actual, matcher|
209
- to_node = node.send_node
210
- corrector_explicit(to_node, actual, matcher, to_node)
211
- end
212
- end
213
-
214
- def corrector_explicit(to_node, actual, matcher, block_child)
215
- lambda do |corrector|
216
- replacement_matcher = replacement_matcher(to_node)
217
- corrector.replace(matcher.loc.expression, replacement_matcher)
218
- move_predicate(corrector, actual, matcher, block_child)
219
- corrector.replace(to_node.loc.selector, 'to')
220
- end
186
+ def corrector_explicit(corrector, to_node, actual, matcher, block_child)
187
+ replacement_matcher = replacement_matcher(to_node)
188
+ corrector.replace(matcher.loc.expression, replacement_matcher)
189
+ move_predicate(corrector, actual, matcher, block_child)
190
+ corrector.replace(to_node.loc.selector, 'to')
221
191
  end
222
192
 
223
193
  def move_predicate(corrector, actual, matcher, block_child)
@@ -261,7 +231,6 @@ module RuboCop
261
231
  end
262
232
  end
263
233
  end
264
- # rubocop:enable Metrics/ModuleLength
265
234
 
266
235
  # Prefer using predicate matcher over using predicate method directly.
267
236
  #
@@ -277,12 +246,12 @@ module RuboCop
277
246
  # expect(foo).to be_something
278
247
  #
279
248
  # # also good - It checks "true" strictly.
280
- # expect(foo).to be(true)
249
+ # expect(foo.something?).to be(true)
281
250
  #
282
251
  # @example Strict: false, EnforcedStyle: inflected
283
252
  # # bad
284
253
  # expect(foo.something?).to be_truthy
285
- # expect(foo).to be(true)
254
+ # expect(foo.something?).to be(true)
286
255
  #
287
256
  # # good
288
257
  # expect(foo).to be_something
@@ -301,6 +270,7 @@ module RuboCop
301
270
  # # good - the above code is rewritten to it by this cop
302
271
  # expect(foo.something?).to be_truthy
303
272
  class PredicateMatcher < Cop
273
+ extend AutoCorrector
304
274
  include ConfigurableEnforcedStyle
305
275
  include InflectedHelper
306
276
  include ExplicitHelper