rubocop-rspec 2.25.0 → 2.26.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afb5cf0c88af50530fc023549eb7e9083db3ca2314553f1fca912ea2a3c47bdb
4
- data.tar.gz: ba30f926d9cd3056e786f724140ac4358af527496b2e783fcc5c8e541adc9d13
3
+ metadata.gz: 5f2e44d1764d0cea711adf5ea346e895d6d6ff805de65da2a85ea842a046fce0
4
+ data.tar.gz: 382cbaeabb62b1fb6e11298d99800c0db8de3350eeec154194d8a018ac74f1ac
5
5
  SHA512:
6
- metadata.gz: cd7955549b3b95b481eb5dea24b98f72e1b802546f8e090695a782a20b0ee8d1d0bcca9a6089f3a46718c5a14967de6c8473709ecea72d8aa5eae85e2cb5bd6f
7
- data.tar.gz: 2beb193cf65884c363c2ece1a3a7ba5db39eecc3a579724bd39f29696ab29276def06261363b6a6290d378743e0b79d414e056b65f0a8a9e2e4215a417d9b978
6
+ metadata.gz: ef7d2b26f8cee852c069f9d2f847c6041ae083fcb4a4940adde810687c8745a612d9abe7445ee3a8548b2047b7d13ac050f8589821f478d0443939ba38830901
7
+ data.tar.gz: ef690c9604c7d21cf95f997112052af66190569945a2065d8ac299f5b3b1aa960130c8f03a337482646983ec0b7632390074837723db23bd21047c51a1984ae8
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 2.26.0 (2024-01-04)
6
+
7
+ - Add new `RSpec/RedundantPredicateMatcher` cop. ([@ydah])
8
+ - Add new `RSpec/RemoveConst` cop. ([@swelther])
9
+ - Add support for correcting "it will" (future tense) for `RSpec/ExampleWording`. ([@jdufresne])
10
+ - Add support for `symbol` style for `RSpec/SharedExamples`. ([@jessieay])
11
+ - Ensure `PendingWithoutReason` can detect violations inside shared groups. ([@robinaugh])
12
+
5
13
  ## 2.25.0 (2023-10-27)
6
14
 
7
15
  - Add support single quoted string and percent string and heredoc for `RSpec/Rails/HttpStatus`. ([@ydah])
@@ -855,7 +863,9 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
855
863
  [@ignaciovillaverde]: https://github.com/ignaciovillaverde
856
864
  [@jaredbeck]: https://github.com/jaredbeck
857
865
  [@jaredmoody]: https://github.com/jaredmoody
866
+ [@jdufresne]: https://github.com/jdufresne
858
867
  [@jeffreyc]: https://github.com/jeffreyc
868
+ [@jessieay]: https://github.com/jessieay
859
869
  [@jfragoulis]: https://github.com/jfragoulis
860
870
  [@johnny-miyake]: https://github.com/johnny-miyake
861
871
  [@jojos003]: https://github.com/jojos003
@@ -897,6 +907,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
897
907
  [@rafix02]: https://github.com/Rafix02
898
908
  [@redross]: https://github.com/redross
899
909
  [@renanborgescampos]: https://github.com/renanborgescampos
910
+ [@robinaugh]: https://github.com/robinaugh
900
911
  [@robotdana]: https://github.com/robotdana
901
912
  [@rolfschmidt]: https://github.com/rolfschmidt
902
913
  [@rrosenblum]: https://github.com/rrosenblum
@@ -909,6 +920,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
909
920
  [@smcgivern]: https://github.com/smcgivern
910
921
  [@splattael]: https://github.com/splattael
911
922
  [@stephannv]: https://github.com/stephannv
923
+ [@swelther]: https://github.com/swelther
912
924
  [@t3h2mas]: https://github.com/t3h2mas
913
925
  [@tdeo]: https://github.com/tdeo
914
926
  [@tejasbubane]: https://github.com/tejasbubane
data/config/default.yml CHANGED
@@ -178,7 +178,7 @@ RSpec/BeNil:
178
178
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeNil
179
179
 
180
180
  RSpec/BeforeAfterAll:
181
- Description: Check that before/after(:all) isn't being used.
181
+ Description: Check that before/after(:all/:context) isn't being used.
182
182
  Enabled: true
183
183
  Exclude:
184
184
  - "**/spec/spec_helper.rb"
@@ -771,6 +771,18 @@ RSpec/RedundantAround:
771
771
  VersionAdded: '2.19'
772
772
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantAround
773
773
 
774
+ RSpec/RedundantPredicateMatcher:
775
+ Description: Checks for redundant predicate matcher.
776
+ Enabled: pending
777
+ VersionAdded: '2.26'
778
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RedundantPredicateMatcher
779
+
780
+ RSpec/RemoveConst:
781
+ Description: Checks that `remove_const` is not used in specs.
782
+ Enabled: pending
783
+ VersionAdded: '2.26'
784
+ Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/RemoveConst
785
+
774
786
  RSpec/RepeatedDescription:
775
787
  Description: Check for repeated description strings in example groups.
776
788
  Enabled: true
@@ -832,9 +844,14 @@ RSpec/SharedContext:
832
844
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedContext
833
845
 
834
846
  RSpec/SharedExamples:
835
- Description: Enforces use of string to titleize shared examples.
847
+ Description: Checks for consistent style for shared example names.
836
848
  Enabled: true
849
+ EnforcedStyle: string
850
+ SupportedStyles:
851
+ - string
852
+ - symbol
837
853
  VersionAdded: '1.25'
854
+ VersionChanged: '2.26'
838
855
  Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/SharedExamples
839
856
 
840
857
  RSpec/SingleArgumentMessageChain:
@@ -32,17 +32,17 @@ module RuboCop
32
32
  'or `%<arg>s.run`.'
33
33
 
34
34
  # @!method hook_block(node)
35
- def_node_matcher :hook_block, <<-PATTERN
35
+ def_node_matcher :hook_block, <<~PATTERN
36
36
  (block (send nil? :around sym ?) (args $...) ...)
37
37
  PATTERN
38
38
 
39
39
  # @!method hook_numblock(node)
40
- def_node_matcher :hook_numblock, <<-PATTERN
40
+ def_node_matcher :hook_numblock, <<~PATTERN
41
41
  (numblock (send nil? :around sym ?) ...)
42
42
  PATTERN
43
43
 
44
44
  # @!method find_arg_usage(node)
45
- def_node_search :find_arg_usage, <<-PATTERN
45
+ def_node_search :find_arg_usage, <<~PATTERN
46
46
  {(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
47
47
  PATTERN
48
48
 
@@ -24,7 +24,7 @@ module RuboCop
24
24
  RESTRICT_ON_SEND = Runners.all
25
25
 
26
26
  # @!method be_without_args(node)
27
- def_node_matcher :be_without_args, <<-PATTERN
27
+ def_node_matcher :be_without_args, <<~PATTERN
28
28
  (send _ #Runners.all $(send nil? :be))
29
29
  PATTERN
30
30
 
@@ -30,7 +30,7 @@ module RuboCop
30
30
  RESTRICT_ON_SEND = %i[eq].freeze
31
31
 
32
32
  # @!method eq_type_with_identity?(node)
33
- def_node_matcher :eq_type_with_identity?, <<-PATTERN
33
+ def_node_matcher :eq_type_with_identity?, <<~PATTERN
34
34
  (send nil? :eq {true false nil})
35
35
  PATTERN
36
36
 
@@ -44,7 +44,7 @@ module RuboCop
44
44
  RESTRICT_ON_SEND = %i[to].freeze
45
45
 
46
46
  # @!method eql_type_with_identity(node)
47
- def_node_matcher :eql_type_with_identity, <<-PATTERN
47
+ def_node_matcher :eql_type_with_identity, <<~PATTERN
48
48
  (send _ :to $(send nil? :eql {true false int float sym nil}))
49
49
  PATTERN
50
50
 
@@ -33,12 +33,12 @@ module RuboCop
33
33
  RESTRICT_ON_SEND = %i[be be_nil].freeze
34
34
 
35
35
  # @!method be_nil_matcher?(node)
36
- def_node_matcher :be_nil_matcher?, <<-PATTERN
36
+ def_node_matcher :be_nil_matcher?, <<~PATTERN
37
37
  (send nil? :be_nil)
38
38
  PATTERN
39
39
 
40
40
  # @!method nil_value_expectation?(node)
41
- def_node_matcher :nil_value_expectation?, <<-PATTERN
41
+ def_node_matcher :nil_value_expectation?, <<~PATTERN
42
42
  (send nil? :be nil)
43
43
  PATTERN
44
44
 
@@ -3,22 +3,16 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
- # Check that before/after(:all) isn't being used.
6
+ # Check that before/after(:all/:context) isn't being used.
7
7
  #
8
8
  # @example
9
- # # bad
10
- # #
11
- # # Faster but risk of state leaking between examples
12
- # #
9
+ # # bad - Faster but risk of state leaking between examples
13
10
  # describe MyClass do
14
11
  # before(:all) { Widget.create }
15
- # after(:all) { Widget.delete_all }
12
+ # after(:context) { Widget.delete_all }
16
13
  # end
17
14
  #
18
- # # good
19
- # #
20
- # # Slower but examples are properly isolated
21
- # #
15
+ # # good - Slower but examples are properly isolated
22
16
  # describe MyClass do
23
17
  # before(:each) { Widget.create }
24
18
  # after(:each) { Widget.delete_all }
@@ -30,11 +24,11 @@ module RuboCop
30
24
  '`use_transactional_fixtures` is enabled, then records created ' \
31
25
  'in `%<hook>s` are not automatically rolled back.'
32
26
 
33
- RESTRICT_ON_SEND = %i[before after].freeze
27
+ RESTRICT_ON_SEND = Set[:before, :after].freeze
34
28
 
35
29
  # @!method before_or_after_all(node)
36
- def_node_matcher :before_or_after_all, <<-PATTERN
37
- $(send _ {:before :after} (sym {:all :context}))
30
+ def_node_matcher :before_or_after_all, <<~PATTERN
31
+ $(send _ RESTRICT_ON_SEND (sym {:all :context}))
38
32
  PATTERN
39
33
 
40
34
  def on_send(node)
@@ -58,12 +58,12 @@ module RuboCop
58
58
  }.freeze
59
59
 
60
60
  # @!method capybara_speak(node)
61
- def_node_matcher :capybara_speak, <<-PATTERN
61
+ def_node_matcher :capybara_speak, <<~PATTERN
62
62
  {#{MAP.keys.map(&:inspect).join(' ')}}
63
63
  PATTERN
64
64
 
65
65
  # @!method feature_method(node)
66
- def_node_matcher :feature_method, <<-PATTERN
66
+ def_node_matcher :feature_method, <<~PATTERN
67
67
  (block
68
68
  $(send #rspec? $#capybara_speak ...)
69
69
  ...)
@@ -66,14 +66,14 @@ module RuboCop
66
66
  RESTRICT_ON_SEND = CHANGE_METHODS.freeze
67
67
 
68
68
  # @!method expect_change_with_arguments(node)
69
- def_node_matcher :expect_change_with_arguments, <<-PATTERN
69
+ def_node_matcher :expect_change_with_arguments, <<~PATTERN
70
70
  (send
71
71
  $(send nil? CHANGE_METHODS ...) :by
72
72
  (int 0))
73
73
  PATTERN
74
74
 
75
75
  # @!method expect_change_with_block(node)
76
- def_node_matcher :expect_change_with_block, <<-PATTERN
76
+ def_node_matcher :expect_change_with_block, <<~PATTERN
77
77
  (send
78
78
  (block
79
79
  $(send nil? CHANGE_METHODS)
@@ -83,7 +83,7 @@ module RuboCop
83
83
  PATTERN
84
84
 
85
85
  # @!method change_nodes(node)
86
- def_node_search :change_nodes, <<-PATTERN
86
+ def_node_search :change_nodes, <<~PATTERN
87
87
  $(send nil? CHANGE_METHODS ...)
88
88
  PATTERN
89
89
 
@@ -30,7 +30,7 @@ module RuboCop
30
30
  MSG = 'Use `describe` for testing methods.'
31
31
 
32
32
  # @!method context_method(node)
33
- def_node_matcher :context_method, <<-PATTERN
33
+ def_node_matcher :context_method, <<~PATTERN
34
34
  (block
35
35
  (send #rspec? :context
36
36
  ${(str #method_name?) (dstr (str #method_name?) ...)}
@@ -38,7 +38,7 @@ module RuboCop
38
38
  ...)
39
39
  PATTERN
40
40
 
41
- def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
41
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
42
42
  context_method(node) do |context|
43
43
  add_offense(context) do |corrector|
44
44
  corrector.replace(node.send_node.loc.selector, 'describe')
@@ -61,7 +61,7 @@ module RuboCop
61
61
  MSG = 'Context description should match %<patterns>s.'
62
62
 
63
63
  # @!method context_wording(node)
64
- def_node_matcher :context_wording, <<-PATTERN
64
+ def_node_matcher :context_wording, <<~PATTERN
65
65
  (block (send #rspec? { :context :shared_context } $({str dstr xstr} ...) ...) ...)
66
66
  PATTERN
67
67
 
@@ -22,7 +22,7 @@ module RuboCop
22
22
  RESTRICT_ON_SEND = %i[describe].freeze
23
23
 
24
24
  # @!method describe_symbol?(node)
25
- def_node_matcher :describe_symbol?, <<-PATTERN
25
+ def_node_matcher :describe_symbol?, <<~PATTERN
26
26
  (send #rspec? :describe $sym ...)
27
27
  PATTERN
28
28
 
@@ -63,7 +63,7 @@ module RuboCop
63
63
  MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
64
64
 
65
65
  # @!method common_instance_exec_closure?(node)
66
- def_node_matcher :common_instance_exec_closure?, <<-PATTERN
66
+ def_node_matcher :common_instance_exec_closure?, <<~PATTERN
67
67
  (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
68
68
  PATTERN
69
69
 
@@ -75,7 +75,7 @@ module RuboCop
75
75
  def_node_matcher :scope_changing_syntax?, '{def class module}'
76
76
 
77
77
  # @!method described_constant(node)
78
- def_node_matcher :described_constant, <<-PATTERN
78
+ def_node_matcher :described_constant, <<~PATTERN
79
79
  (block (send _ :describe $(const ...) ...) (args) $_)
80
80
  PATTERN
81
81
 
@@ -148,15 +148,15 @@ module RuboCop
148
148
  end
149
149
 
150
150
  def offensive_described_class?(node)
151
- return unless node.const_type?
151
+ return false unless node.const_type?
152
152
 
153
153
  # E.g. `described_class::CONSTANT`
154
- return if contains_described_class?(node)
154
+ return false if contains_described_class?(node)
155
155
 
156
156
  nearest_described_class, = node.each_ancestor(:block)
157
157
  .map { |ancestor| described_constant(ancestor) }.find(&:itself)
158
158
 
159
- return if nearest_described_class.equal?(node)
159
+ return false if nearest_described_class.equal?(node)
160
160
 
161
161
  full_const_name(nearest_described_class) == full_const_name(node)
162
162
  end
@@ -162,7 +162,7 @@ module RuboCop
162
162
  end
163
163
 
164
164
  def conditionals_with_examples?(body)
165
- return unless body.begin_type? || body.case_type?
165
+ return false unless body.begin_type? || body.case_type?
166
166
 
167
167
  body.each_descendant(:if, :case).any? do |condition_node|
168
168
  examples_in_branches?(condition_node)
@@ -170,7 +170,7 @@ module RuboCop
170
170
  end
171
171
 
172
172
  def examples_in_branches?(condition_node)
173
- return if !condition_node.if_type? && !condition_node.case_type?
173
+ return false if !condition_node.if_type? && !condition_node.case_type?
174
174
 
175
175
  condition_node.branches.any? { |branch| examples?(branch) }
176
176
  end
@@ -71,8 +71,8 @@ module RuboCop
71
71
 
72
72
  def next_one_line_example?(node)
73
73
  next_sibling = node.right_sibling
74
- return unless next_sibling
75
- return unless example?(next_sibling)
74
+ return false unless next_sibling
75
+ return false unless example?(next_sibling)
76
76
 
77
77
  next_sibling.single_line?
78
78
  end
@@ -22,6 +22,9 @@ module RuboCop
22
22
  # it 'should find nothing' do
23
23
  # end
24
24
  #
25
+ # it 'will find nothing' do
26
+ # end
27
+ #
25
28
  # # good
26
29
  # it 'finds nothing' do
27
30
  # end
@@ -47,25 +50,30 @@ module RuboCop
47
50
  extend AutoCorrector
48
51
 
49
52
  MSG_SHOULD = 'Do not use should when describing your tests.'
53
+ MSG_WILL = 'Do not use the future tense when describing your tests.'
50
54
  MSG_IT = "Do not repeat 'it' when describing your tests."
51
55
  MSG_INSUFFICIENT_DESCRIPTION = 'Your example description is ' \
52
56
  'insufficient.'
53
57
 
54
58
  SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
59
+ WILL_PREFIX = /\A(?:will|won't)\b/i.freeze
55
60
  IT_PREFIX = /\Ait /i.freeze
56
61
 
57
62
  # @!method it_description(node)
58
- def_node_matcher :it_description, <<-PATTERN
63
+ def_node_matcher :it_description, <<~PATTERN
59
64
  (block (send _ :it ${
60
65
  (str $_)
61
66
  (dstr (str $_ ) ...)
62
67
  } ...) ...)
63
68
  PATTERN
64
69
 
70
+ # rubocop:disable Metrics/MethodLength
65
71
  def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
66
72
  it_description(node) do |description_node, message|
67
73
  if message.match?(SHOULD_PREFIX)
68
74
  add_wording_offense(description_node, MSG_SHOULD)
75
+ elsif message.match?(WILL_PREFIX)
76
+ add_wording_offense(description_node, MSG_WILL)
69
77
  elsif message.match?(IT_PREFIX)
70
78
  add_wording_offense(description_node, MSG_IT)
71
79
  elsif insufficient_docstring?(description_node)
@@ -74,6 +82,7 @@ module RuboCop
74
82
  end
75
83
  end
76
84
  end
85
+ # rubocop:enable Metrics/MethodLength
77
86
 
78
87
  private
79
88
 
@@ -100,7 +109,7 @@ module RuboCop
100
109
  def replacement_text(node)
101
110
  text = text(node)
102
111
 
103
- if text.match?(SHOULD_PREFIX)
112
+ if text.match?(SHOULD_PREFIX) || text.match?(WILL_PREFIX)
104
113
  RuboCop::RSpec::Wording.new(
105
114
  text,
106
115
  ignore: ignored_words,
@@ -29,7 +29,7 @@ module RuboCop
29
29
  MSG = 'Excessive whitespace.'
30
30
 
31
31
  # @!method example_description(node)
32
- def_node_matcher :example_description, <<-PATTERN
32
+ def_node_matcher :example_description, <<~PATTERN
33
33
  (send _ {#Examples.all #ExampleGroups.all} ${
34
34
  $str
35
35
  $(dstr ({str dstr `sym} ...) ...)
@@ -38,12 +38,12 @@ module RuboCop
38
38
  RESTRICT_ON_SEND = %i[change].freeze
39
39
 
40
40
  # @!method expect_change_with_arguments(node)
41
- def_node_matcher :expect_change_with_arguments, <<-PATTERN
41
+ def_node_matcher :expect_change_with_arguments, <<~PATTERN
42
42
  (send nil? :change $_ ({sym str} $_))
43
43
  PATTERN
44
44
 
45
45
  # @!method expect_change_with_block(node)
46
- def_node_matcher :expect_change_with_block, <<-PATTERN
46
+ def_node_matcher :expect_change_with_block, <<~PATTERN
47
47
  (block
48
48
  (send nil? :change)
49
49
  (args)
@@ -56,7 +56,7 @@ module RuboCop
56
56
  MSG = 'Focused spec found.'
57
57
 
58
58
  # @!method focusable_selector?(node)
59
- def_node_matcher :focusable_selector?, <<-PATTERN
59
+ def_node_matcher :focusable_selector?, <<~PATTERN
60
60
  {
61
61
  #ExampleGroups.regular
62
62
  #ExampleGroups.skipped
@@ -68,7 +68,7 @@ module RuboCop
68
68
  PATTERN
69
69
 
70
70
  # @!method metadata(node)
71
- def_node_matcher :metadata, <<-PATTERN
71
+ def_node_matcher :metadata, <<~PATTERN
72
72
  {(send #rspec? #focusable_selector? <$(sym :focus) ...>)
73
73
  (send #rspec? #focusable_selector? ... (hash <$(pair (sym :focus) true) ...>))}
74
74
  PATTERN
@@ -66,12 +66,12 @@ module RuboCop
66
66
  EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
67
67
 
68
68
  # @!method scoped_hook(node)
69
- def_node_matcher :scoped_hook, <<-PATTERN
69
+ def_node_matcher :scoped_hook, <<~PATTERN
70
70
  ({block numblock} $(send _ #Hooks.all (sym ${:each :example})) ...)
71
71
  PATTERN
72
72
 
73
73
  # @!method unscoped_hook(node)
74
- def_node_matcher :unscoped_hook, <<-PATTERN
74
+ def_node_matcher :unscoped_hook, <<~PATTERN
75
75
  ({block numblock} $(send _ #Hooks.all) ...)
76
76
  PATTERN
77
77
 
@@ -28,7 +28,7 @@ module RuboCop
28
28
  MSG = 'Move `%<hook>s` above the examples in the group.'
29
29
 
30
30
  # @!method example_or_group?(node)
31
- def_node_matcher :example_or_group?, <<-PATTERN
31
+ def_node_matcher :example_or_group?, <<~PATTERN
32
32
  {
33
33
  ({block numblock} {
34
34
  (send #rspec? #ExampleGroups.all ...)
@@ -22,7 +22,7 @@ module RuboCop
22
22
  RESTRICT_ON_SEND = %i[is_expected should should_not].freeze
23
23
 
24
24
  # @!method lambda?(node)
25
- def_node_matcher :lambda?, <<-PATTERN
25
+ def_node_matcher :lambda?, <<~PATTERN
26
26
  {
27
27
  (send (const nil? :Proc) :new)
28
28
  (send nil? {:proc :lambda})
@@ -33,7 +33,7 @@ module RuboCop
33
33
  def_node_matcher :lambda_subject?, '(block #lambda? ...)'
34
34
 
35
35
  # @!method implicit_expect(node)
36
- def_node_matcher :implicit_expect, <<-PATTERN
36
+ def_node_matcher :implicit_expect, <<~PATTERN
37
37
  $(send nil? {:is_expected :should :should_not} ...)
38
38
  PATTERN
39
39
 
@@ -31,7 +31,7 @@ module RuboCop
31
31
  RESTRICT_ON_SEND = Runners.all + %i[should should_not]
32
32
 
33
33
  # @!method implicit_expect(node)
34
- def_node_matcher :implicit_expect, <<-PATTERN
34
+ def_node_matcher :implicit_expect, <<~PATTERN
35
35
  {
36
36
  (send nil? ${:should :should_not} ...)
37
37
  (send (send nil? $:is_expected) #Runners.all ...)
@@ -78,12 +78,12 @@ module RuboCop
78
78
  ].freeze
79
79
 
80
80
  # @!method explicit_unnamed_subject?(node)
81
- def_node_matcher :explicit_unnamed_subject?, <<-PATTERN
81
+ def_node_matcher :explicit_unnamed_subject?, <<~PATTERN
82
82
  (send nil? :expect (send nil? :subject))
83
83
  PATTERN
84
84
 
85
85
  # @!method implicit_subject?(node)
86
- def_node_matcher :implicit_subject?, <<-PATTERN
86
+ def_node_matcher :implicit_subject?, <<~PATTERN
87
87
  (send nil? {:should :should_not :is_expected} ...)
88
88
  PATTERN
89
89
 
@@ -25,7 +25,7 @@ module RuboCop
25
25
  'with `have_received`.'
26
26
 
27
27
  # @!method null_double(node)
28
- def_node_search :null_double, <<-PATTERN
28
+ def_node_search :null_double, <<~PATTERN
29
29
  (lvasgn $_
30
30
  (send
31
31
  $(send nil? :instance_double
@@ -33,7 +33,7 @@ module RuboCop
33
33
  PATTERN
34
34
 
35
35
  # @!method have_received_usage(node)
36
- def_node_search :have_received_usage, <<-PATTERN
36
+ def_node_search :have_received_usage, <<~PATTERN
37
37
  (send
38
38
  (send nil? :expect
39
39
  (lvar $_)) :to
@@ -52,12 +52,12 @@ module RuboCop
52
52
  'a method call, or a local variable (if possible).'
53
53
 
54
54
  # @!method dynamic_class?(node)
55
- def_node_matcher :dynamic_class?, <<-PATTERN
55
+ def_node_matcher :dynamic_class?, <<~PATTERN
56
56
  (block (send (const nil? :Class) :new ...) ...)
57
57
  PATTERN
58
58
 
59
59
  # @!method custom_matcher?(node)
60
- def_node_matcher :custom_matcher?, <<-PATTERN
60
+ def_node_matcher :custom_matcher?, <<~PATTERN
61
61
  (block {
62
62
  (send nil? :matcher sym)
63
63
  (send (const (const nil? :RSpec) :Matchers) :define sym)
@@ -21,7 +21,7 @@ module RuboCop
21
21
  'of iterating over an array.'
22
22
 
23
23
  # @!method each?(node)
24
- def_node_matcher :each?, <<-PATTERN
24
+ def_node_matcher :each?, <<~PATTERN
25
25
  (block
26
26
  (send ... :each)
27
27
  (args (arg $_))
@@ -30,14 +30,14 @@ module RuboCop
30
30
  PATTERN
31
31
 
32
32
  # @!method each_numblock?(node)
33
- def_node_matcher :each_numblock?, <<-PATTERN
33
+ def_node_matcher :each_numblock?, <<~PATTERN
34
34
  (numblock
35
35
  (send ... :each) _ $(...)
36
36
  )
37
37
  PATTERN
38
38
 
39
39
  # @!method expectation?(node)
40
- def_node_matcher :expectation?, <<-PATTERN
40
+ def_node_matcher :expectation?, <<~PATTERN
41
41
  (send (send nil? :expect (lvar %)) :to ...)
42
42
  PATTERN
43
43
 
@@ -36,7 +36,7 @@ module RuboCop
36
36
  MSG = 'Move `let` before the examples in the group.'
37
37
 
38
38
  # @!method example_or_group?(node)
39
- def_node_matcher :example_or_group?, <<-PATTERN
39
+ def_node_matcher :example_or_group?, <<~PATTERN
40
40
  {
41
41
  (block (send nil? {#ExampleGroups.all #Examples.all} ...) ...)
42
42
  (send nil? #Includes.examples ...)
@@ -37,7 +37,7 @@ module RuboCop
37
37
  PATTERN
38
38
 
39
39
  # @!method let_bang(node)
40
- def_node_matcher :let_bang, <<-PATTERN
40
+ def_node_matcher :let_bang, <<~PATTERN
41
41
  {
42
42
  (block $(send nil? :let! {(sym $_) (str $_)}) ...)
43
43
  $(send nil? :let! {(sym $_) (str $_)} block_pass)
@@ -33,7 +33,7 @@ module RuboCop
33
33
  RESTRICT_ON_SEND = %i[to].freeze
34
34
 
35
35
  # @!method message_expectation(node)
36
- def_node_matcher :message_expectation, <<-PATTERN
36
+ def_node_matcher :message_expectation, <<~PATTERN
37
37
  (send $(send nil? {:expect :allow} ...) :to #receive_message?)
38
38
  PATTERN
39
39
 
@@ -8,7 +8,7 @@ module RuboCop
8
8
  extend RuboCop::NodePattern::Macros
9
9
 
10
10
  # @!method skipped_in_metadata?(node)
11
- def_node_matcher :skipped_in_metadata?, <<-PATTERN
11
+ def_node_matcher :skipped_in_metadata?, <<~PATTERN
12
12
  {
13
13
  (send _ _ <(sym {:skip :pending}) ...>)
14
14
  (send _ _ ... (hash <(pair (sym {:skip :pending}) { true str dstr }) ...>))
@@ -30,7 +30,7 @@ module RuboCop
30
30
  #
31
31
  # @param node [RuboCop::AST::Node]
32
32
  # @return [Array<RuboCop::AST::Node>] matching nodes
33
- def_node_matcher :skip_or_pending_inside_block?, <<-PATTERN
33
+ def_node_matcher :skip_or_pending_inside_block?, <<~PATTERN
34
34
  (block <(send nil? {:skip :pending} ...) ...>)
35
35
  PATTERN
36
36
  end