rubocop-rspec 1.32.0 → 1.33.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile +2 -0
  4. data/Rakefile +2 -0
  5. data/config/default.yml +6 -0
  6. data/lib/rubocop-rspec.rb +3 -0
  7. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +1 -1
  8. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +1 -1
  9. data/lib/rubocop/cop/rspec/any_instance.rb +3 -1
  10. data/lib/rubocop/cop/rspec/around_block.rb +4 -2
  11. data/lib/rubocop/cop/rspec/be.rb +4 -2
  12. data/lib/rubocop/cop/rspec/be_eql.rb +3 -1
  13. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -1
  14. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -3
  15. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -3
  16. data/lib/rubocop/cop/rspec/context_wording.rb +2 -2
  17. data/lib/rubocop/cop/rspec/describe_class.rb +4 -4
  18. data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
  19. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -2
  20. data/lib/rubocop/cop/rspec/described_class.rb +3 -3
  21. data/lib/rubocop/cop/rspec/dialect.rb +76 -0
  22. data/lib/rubocop/cop/rspec/empty_example_group.rb +1 -1
  23. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  24. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
  25. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
  26. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +1 -1
  27. data/lib/rubocop/cop/rspec/example_length.rb +1 -1
  28. data/lib/rubocop/cop/rspec/example_without_description.rb +2 -2
  29. data/lib/rubocop/cop/rspec/example_wording.rb +2 -2
  30. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -1
  31. data/lib/rubocop/cop/rspec/expect_change.rb +2 -2
  32. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
  33. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  34. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +21 -40
  35. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +2 -2
  36. data/lib/rubocop/cop/rspec/file_path.rb +2 -2
  37. data/lib/rubocop/cop/rspec/focus.rb +3 -3
  38. data/lib/rubocop/cop/rspec/hook_argument.rb +4 -6
  39. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -5
  40. data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -2
  41. data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -1
  42. data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
  43. data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
  44. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +4 -2
  45. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -1
  46. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
  47. data/lib/rubocop/cop/rspec/leading_subject.rb +1 -2
  48. data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -5
  49. data/lib/rubocop/cop/rspec/let_setup.rb +1 -1
  50. data/lib/rubocop/cop/rspec/message_chain.rb +3 -1
  51. data/lib/rubocop/cop/rspec/message_expectation.rb +1 -1
  52. data/lib/rubocop/cop/rspec/message_spies.rb +3 -4
  53. data/lib/rubocop/cop/rspec/missing_example_group_argument.rb +1 -1
  54. data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -1
  55. data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
  56. data/lib/rubocop/cop/rspec/multiple_subjects.rb +6 -2
  57. data/lib/rubocop/cop/rspec/named_subject.rb +1 -1
  58. data/lib/rubocop/cop/rspec/nested_groups.rb +3 -4
  59. data/lib/rubocop/cop/rspec/not_to_not.rb +3 -1
  60. data/lib/rubocop/cop/rspec/overwriting_setup.rb +1 -1
  61. data/lib/rubocop/cop/rspec/pending.rb +3 -3
  62. data/lib/rubocop/cop/rspec/predicate_matcher.rb +17 -14
  63. data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -2
  64. data/lib/rubocop/cop/rspec/receive_counts.rb +5 -6
  65. data/lib/rubocop/cop/rspec/receive_never.rb +4 -7
  66. data/lib/rubocop/cop/rspec/repeated_description.rb +3 -1
  67. data/lib/rubocop/cop/rspec/repeated_example.rb +3 -1
  68. data/lib/rubocop/cop/rspec/return_from_stub.rb +2 -2
  69. data/lib/rubocop/cop/rspec/scattered_let.rb +1 -1
  70. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  71. data/lib/rubocop/cop/rspec/shared_context.rb +2 -2
  72. data/lib/rubocop/cop/rspec/shared_examples.rb +7 -7
  73. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +3 -1
  74. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -1
  75. data/lib/rubocop/cop/rspec/unspecified_exception.rb +5 -3
  76. data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -2
  77. data/lib/rubocop/cop/rspec/void_expect.rb +1 -1
  78. data/lib/rubocop/cop/rspec/yield.rb +2 -4
  79. data/lib/rubocop/cop/rspec_cops.rb +3 -0
  80. data/lib/rubocop/rspec.rb +2 -0
  81. data/lib/rubocop/rspec/blank_line_separation.rb +3 -1
  82. data/lib/rubocop/rspec/config_formatter.rb +3 -1
  83. data/lib/rubocop/rspec/description_extractor.rb +3 -1
  84. data/lib/rubocop/rspec/factory_bot.rb +58 -0
  85. data/lib/rubocop/rspec/final_end_location.rb +2 -0
  86. data/lib/rubocop/rspec/inject.rb +2 -0
  87. data/lib/rubocop/rspec/language.rb +9 -2
  88. data/lib/rubocop/rspec/top_level_describe.rb +2 -0
  89. data/lib/rubocop/rspec/version.rb +1 -1
  90. data/rubocop-rspec.gemspec +3 -1
  91. data/spec/project/changelog_spec.rb +2 -0
  92. data/spec/project/default_config_spec.rb +2 -0
  93. data/spec/project/project_requires_spec.rb +2 -0
  94. data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +22 -37
  95. data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +21 -36
  96. data/spec/rubocop/cop/rspec/any_instance_spec.rb +2 -0
  97. data/spec/rubocop/cop/rspec/around_block_spec.rb +2 -0
  98. data/spec/rubocop/cop/rspec/be_eql_spec.rb +25 -4
  99. data/spec/rubocop/cop/rspec/be_spec.rb +2 -0
  100. data/spec/rubocop/cop/rspec/before_after_all_spec.rb +2 -0
  101. data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +2 -0
  102. data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +2 -0
  103. data/spec/rubocop/cop/rspec/context_wording_spec.rb +32 -0
  104. data/spec/rubocop/cop/rspec/describe_class_spec.rb +2 -0
  105. data/spec/rubocop/cop/rspec/describe_method_spec.rb +2 -0
  106. data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +2 -0
  107. data/spec/rubocop/cop/rspec/described_class_spec.rb +4 -1
  108. data/spec/rubocop/cop/rspec/dialect_spec.rb +78 -0
  109. data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +40 -21
  110. data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +77 -69
  111. data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +24 -19
  112. data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +16 -19
  113. data/spec/rubocop/cop/rspec/example_length_spec.rb +2 -0
  114. data/spec/rubocop/cop/rspec/example_without_description_spec.rb +2 -0
  115. data/spec/rubocop/cop/rspec/example_wording_spec.rb +45 -24
  116. data/spec/rubocop/cop/rspec/expect_change_spec.rb +22 -14
  117. data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +36 -0
  118. data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +2 -0
  119. data/spec/rubocop/cop/rspec/file_path_spec.rb +2 -0
  120. data/spec/rubocop/cop/rspec/focus_spec.rb +2 -2
  121. data/spec/rubocop/cop/rspec/hook_argument_spec.rb +2 -0
  122. data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +47 -32
  123. data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +20 -19
  124. data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +56 -68
  125. data/spec/rubocop/cop/rspec/instance_spy_spec.rb +16 -15
  126. data/spec/rubocop/cop/rspec/instance_variable_spec.rb +2 -0
  127. data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +2 -0
  128. data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +10 -12
  129. data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +2 -0
  130. data/spec/rubocop/cop/rspec/leading_subject_spec.rb +31 -47
  131. data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +27 -26
  132. data/spec/rubocop/cop/rspec/message_chain_spec.rb +2 -0
  133. data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +2 -0
  134. data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +2 -0
  135. data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +24 -37
  136. data/spec/rubocop/cop/rspec/not_to_not_spec.rb +22 -32
  137. data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +2 -0
  138. data/spec/rubocop/cop/rspec/pending_spec.rb +2 -0
  139. data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +2 -0
  140. data/spec/rubocop/cop/rspec/receive_counts_spec.rb +47 -8
  141. data/spec/rubocop/cop/rspec/receive_never_spec.rb +16 -4
  142. data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +95 -72
  143. data/spec/rubocop/cop/rspec/scattered_let_spec.rb +2 -0
  144. data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +2 -0
  145. data/spec/rubocop/cop/rspec/shared_context_spec.rb +29 -34
  146. data/spec/rubocop/cop/rspec/shared_examples_spec.rb +16 -34
  147. data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +44 -48
  148. data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +2 -0
  149. data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +2 -0
  150. data/spec/rubocop/cop/rspec/void_expect_spec.rb +2 -0
  151. data/spec/rubocop/cop/rspec/yield_spec.rb +22 -21
  152. data/spec/rubocop/rspec/config_formatter_spec.rb +2 -0
  153. data/spec/rubocop/rspec/description_extractor_spec.rb +2 -0
  154. data/spec/rubocop/rspec/language/selector_set_spec.rb +2 -0
  155. data/spec/rubocop/rspec/util/one_spec.rb +2 -0
  156. data/spec/rubocop/rspec/wording_spec.rb +2 -0
  157. data/spec/shared/autocorrect_behavior.rb +2 -0
  158. data/spec/shared/detects_style_behavior.rb +2 -0
  159. data/spec/shared/smoke_test_examples.rb +2 -0
  160. data/spec/spec_helper.rb +2 -0
  161. data/spec/support/expect_offense.rb +3 -1
  162. metadata +8 -4
@@ -20,7 +20,7 @@ module RuboCop
20
20
  # describe "A feature example" do
21
21
  # end
22
22
  class MissingExampleGroupArgument < Cop
23
- MSG = 'The first argument to `%<method>s` should not be empty.'.freeze
23
+ MSG = 'The first argument to `%<method>s` should not be empty.'
24
24
 
25
25
  def on_block(node)
26
26
  return unless example_group?(node)
@@ -26,7 +26,7 @@ module RuboCop
26
26
  include RuboCop::RSpec::TopLevelDescribe
27
27
 
28
28
  MSG = 'Do not use multiple top level describes - '\
29
- 'try to nest them.'.freeze
29
+ 'try to nest them.'
30
30
 
31
31
  def on_top_level_describe(node, _args)
32
32
  return if single_top_level_describe?
@@ -48,7 +48,7 @@ module RuboCop
48
48
  class MultipleExpectations < Cop
49
49
  include ConfigurableMax
50
50
 
51
- MSG = 'Example has too many expectations [%<total>d/%<max>d].'.freeze
51
+ MSG = 'Example has too many expectations [%<total>d/%<max>d].'
52
52
 
53
53
  def_node_search :with_aggregated_failures?, '(sym :aggregate_failures)'
54
54
  def_node_search :disabled_aggregated_failures?, <<-PATTERN
@@ -34,7 +34,9 @@ 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
- MSG = 'Do not set more than one subject per example group'.freeze
37
+ include RangeHelp
38
+
39
+ MSG = 'Do not set more than one subject per example group'
38
40
 
39
41
  def on_block(node)
40
42
  return unless example_group?(node)
@@ -70,7 +72,9 @@ module RuboCop
70
72
 
71
73
  def remove_autocorrect(node)
72
74
  lambda do |corrector|
73
- corrector.remove(node.loc.expression)
75
+ range = range_by_whole_lines(node.source_range,
76
+ include_final_newline: true)
77
+ corrector.remove(range)
74
78
  end
75
79
  end
76
80
  end
@@ -43,7 +43,7 @@ module RuboCop
43
43
  # end
44
44
  class NamedSubject < Cop
45
45
  MSG = 'Name your test subject if you need '\
46
- 'to reference it explicitly.'.freeze
46
+ 'to reference it explicitly.'
47
47
 
48
48
  def_node_matcher :rspec_block?, <<-PATTERN
49
49
  {
@@ -89,14 +89,13 @@ module RuboCop
89
89
  include ConfigurableMax
90
90
  include RuboCop::RSpec::TopLevelDescribe
91
91
 
92
- MSG = 'Maximum example group nesting exceeded ' \
93
- '[%<total>d/%<max>d].'.freeze
92
+ MSG = 'Maximum example group nesting exceeded [%<total>d/%<max>d].'
94
93
 
95
- DEPRECATED_MAX_KEY = 'MaxNesting'.freeze
94
+ DEPRECATED_MAX_KEY = 'MaxNesting'
96
95
 
97
96
  DEPRECATION_WARNING =
98
97
  "Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
99
- 'deprecated in favor of `Max`. Please use that instead.'.freeze
98
+ 'deprecated in favor of `Max`. Please use that instead.'
100
99
 
101
100
  def_node_search :find_contexts, ExampleGroups::ALL.block_pattern
102
101
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -16,7 +18,7 @@ module RuboCop
16
18
  class NotToNot < Cop
17
19
  include ConfigurableEnforcedStyle
18
20
 
19
- MSG = 'Prefer `%<replacement>s` over `%<original>s`.'.freeze
21
+ MSG = 'Prefer `%<replacement>s` over `%<original>s`.'
20
22
 
21
23
  def_node_matcher :not_to_not_offense, '(send _ % ...)'
22
24
 
@@ -22,7 +22,7 @@ module RuboCop
22
22
  # let(:baz) { baz }
23
23
  # let!(:other) { other }
24
24
  class OverwritingSetup < Cop
25
- MSG = '`%<name>s` is already defined.'.freeze
25
+ MSG = '`%<name>s` is already defined.'
26
26
 
27
27
  def_node_matcher :setup?, (Helpers::ALL + Subject::ALL).block_pattern
28
28
  def_node_matcher :first_argument_name, '(send _ _ ({str sym} $_))'
@@ -26,7 +26,7 @@ module RuboCop
26
26
  # describe MyClass do
27
27
  # end
28
28
  class Pending < Cop
29
- MSG = 'Pending spec found.'.freeze
29
+ MSG = 'Pending spec found.'
30
30
 
31
31
  PENDING_EXAMPLES = Examples::PENDING + Examples::SKIPPED \
32
32
  + ExampleGroups::SKIPPED
@@ -37,8 +37,8 @@ module RuboCop
37
37
  PENDING_SYMBOL = s(:sym, :pending)
38
38
 
39
39
  def_node_matcher :metadata, <<-PATTERN
40
- {(send {(const nil? :RSpec) nil?} #{SKIPPABLE_SELECTORS} ... (hash $...))
41
- (send {(const nil? :RSpec) nil?} #{SKIPPABLE_SELECTORS} $...)}
40
+ {(send #{RSPEC} #{SKIPPABLE_SELECTORS} ... (hash $...))
41
+ (send #{RSPEC} #{SKIPPABLE_SELECTORS} $...)}
42
42
  PATTERN
43
43
 
44
44
  def_node_matcher :pending_block?, PENDING_EXAMPLES.send_pattern
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
4
6
  # A helper for `inflected` style
5
7
  module InflectedHelper
8
+ include RuboCop::RSpec::Language
6
9
  extend NodePattern::Macros
7
10
 
8
11
  MSG_INFLECTED = 'Prefer using `%<matcher_name>s` matcher over ' \
9
- '`%<predicate_name>s`.'.freeze
12
+ '`%<predicate_name>s`.'
10
13
 
11
14
  private
12
15
 
@@ -25,7 +28,7 @@ module RuboCop
25
28
  (send nil? :expect {
26
29
  (block $(send !nil? #predicate? ...) ...)
27
30
  $(send !nil? #predicate? ...)})
28
- ${:to :not_to :to_not}
31
+ $#{Runners::ALL.node_pattern_union}
29
32
  $#boolean_matcher?)
30
33
  PATTERN
31
34
 
@@ -86,10 +89,10 @@ module RuboCop
86
89
  end
87
90
 
88
91
  def remove_predicate(corrector, predicate)
89
- range = range_between(
90
- predicate.loc.dot.begin_pos,
91
- predicate.loc.expression.end_pos
92
+ range = predicate.loc.dot.with(
93
+ end_pos: predicate.loc.expression.end_pos
92
94
  )
95
+
93
96
  corrector.remove(range)
94
97
 
95
98
  block_range = block_loc(predicate)
@@ -123,10 +126,11 @@ module RuboCop
123
126
  # A helper for `explicit` style
124
127
  # rubocop:disable Metrics/ModuleLength
125
128
  module ExplicitHelper
129
+ include RuboCop::RSpec::Language
126
130
  extend NodePattern::Macros
127
131
 
128
132
  MSG_EXPLICIT = 'Prefer using `%<predicate_name>s` over ' \
129
- '`%<matcher_name>s` matcher.'.freeze
133
+ '`%<matcher_name>s` matcher.'
130
134
  BUILT_IN_MATCHERS = %w[
131
135
  be_truthy be_falsey be_falsy
132
136
  have_attributes have_received
@@ -160,7 +164,7 @@ module RuboCop
160
164
  def_node_matcher :predicate_matcher?, <<-PATTERN
161
165
  (send
162
166
  (send nil? :expect $!nil?)
163
- {:to :not_to :to_not}
167
+ #{Runners::ALL.node_pattern_union}
164
168
  {$(send nil? #predicate_matcher_name? ...)
165
169
  (block $(send nil? #predicate_matcher_name? ...) ...)})
166
170
  PATTERN
@@ -169,7 +173,7 @@ module RuboCop
169
173
  (block
170
174
  (send
171
175
  (send nil? :expect $!nil?)
172
- {:to :not_to :to_not}
176
+ #{Runners::ALL.node_pattern_union}
173
177
  $(send nil? #predicate_matcher_name?))
174
178
  ...)
175
179
  PATTERN
@@ -299,7 +303,6 @@ module RuboCop
299
303
  include ConfigurableEnforcedStyle
300
304
  include InflectedHelper
301
305
  include ExplicitHelper
302
- include RangeHelp
303
306
 
304
307
  def on_send(node)
305
308
  case style
@@ -330,8 +333,9 @@ module RuboCop
330
333
  # foo 1, 2
331
334
  # ^^^^^
332
335
  def args_loc(send_node)
333
- range_between(send_node.loc.selector.end_pos,
334
- send_node.loc.expression.end_pos)
336
+ send_node.loc.selector.end.with(
337
+ end_pos: send_node.loc.expression.end_pos
338
+ )
335
339
  end
336
340
 
337
341
  # returns block location with whitespace
@@ -342,9 +346,8 @@ module RuboCop
342
346
  parent = send_node.parent
343
347
  return unless parent.block_type?
344
348
 
345
- range_between(
346
- send_node.loc.expression.end_pos,
347
- parent.loc.expression.end_pos
349
+ send_node.loc.expression.end.with(
350
+ end_pos: parent.loc.expression.end_pos
348
351
  )
349
352
  end
350
353
  end
@@ -67,7 +67,7 @@ module RuboCop
67
67
  # :nodoc:
68
68
  class SymbolicStyleChecker
69
69
  MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
70
- 'to describe HTTP status code.'.freeze
70
+ 'to describe HTTP status code.'
71
71
 
72
72
  attr_reader :node
73
73
  def initialize(node)
@@ -105,7 +105,7 @@ module RuboCop
105
105
  # :nodoc:
106
106
  class NumericStyleChecker
107
107
  MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
108
- 'to describe HTTP status code.'.freeze
108
+ 'to describe HTTP status code.'
109
109
 
110
110
  WHITELIST_STATUS = %i[error success missing redirect].freeze
111
111
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -22,9 +24,7 @@ module RuboCop
22
24
  # expect(foo).to receive(:bar).at_most(:twice).times
23
25
  #
24
26
  class ReceiveCounts < Cop
25
- include RangeHelp
26
-
27
- MSG = 'Use `%<alternative>s` instead of `%<original>s`.'.freeze
27
+ MSG = 'Use `%<alternative>s` instead of `%<original>s`.'
28
28
 
29
29
  def_node_matcher :receive_counts, <<-PATTERN
30
30
  (send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times)
@@ -78,9 +78,8 @@ module RuboCop
78
78
  end
79
79
 
80
80
  def range(node, offending_node)
81
- range_between(
82
- offending_node.loc.dot.begin_pos,
83
- node.loc.expression.end_pos
81
+ offending_node.loc.dot.with(
82
+ end_pos: node.loc.expression.end_pos
84
83
  )
85
84
  end
86
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -12,9 +14,7 @@ module RuboCop
12
14
  # expect(foo).not_to receive(:bar)
13
15
  #
14
16
  class ReceiveNever < Cop
15
- include RangeHelp
16
-
17
- MSG = 'Use `not_to receive` instead of `never`.'.freeze
17
+ MSG = 'Use `not_to receive` instead of `never`.'
18
18
 
19
19
  def_node_search :method_on_stub?, '(send nil? :receive ...)'
20
20
 
@@ -30,10 +30,7 @@ module RuboCop
30
30
  def autocorrect(node)
31
31
  lambda do |corrector|
32
32
  corrector.replace(node.parent.loc.selector, 'not_to')
33
- range = range_between(
34
- node.loc.dot.begin_pos,
35
- node.loc.selector.end_pos
36
- )
33
+ range = node.loc.dot.with(end_pos: node.loc.selector.end_pos)
37
34
  corrector.remove(range)
38
35
  end
39
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -28,7 +30,7 @@ module RuboCop
28
30
  # end
29
31
  #
30
32
  class RepeatedDescription < Cop
31
- MSG = "Don't repeat descriptions within an example group.".freeze
33
+ MSG = "Don't repeat descriptions within an example group."
32
34
 
33
35
  def on_block(node)
34
36
  return unless example_group?(node)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -14,7 +16,7 @@ module RuboCop
14
16
  # end
15
17
  #
16
18
  class RepeatedExample < Cop
17
- MSG = "Don't repeat examples within an example group.".freeze
19
+ MSG = "Don't repeat examples within an example group."
18
20
 
19
21
  def on_block(node)
20
22
  return unless example_group?(node)
@@ -36,8 +36,8 @@ module RuboCop
36
36
  class ReturnFromStub < Cop
37
37
  include ConfigurableEnforcedStyle
38
38
 
39
- MSG_AND_RETURN = 'Use `and_return` for static values.'.freeze
40
- MSG_BLOCK = 'Use block for static values.'.freeze
39
+ MSG_AND_RETURN = 'Use `and_return` for static values.'
40
+ MSG_BLOCK = 'Use block for static values.'
41
41
 
42
42
  def_node_search :contains_stub?, '(send nil? :receive (...))'
43
43
  def_node_search :and_return_value, <<-PATTERN
@@ -27,7 +27,7 @@ module RuboCop
27
27
  # end
28
28
  #
29
29
  class ScatteredLet < Cop
30
- MSG = 'Group all let/let! blocks in the example group together.'.freeze
30
+ MSG = 'Group all let/let! blocks in the example group together.'
31
31
 
32
32
  def on_block(node)
33
33
  return unless example_group_with_body?(node)
@@ -23,7 +23,7 @@ module RuboCop
23
23
  # end
24
24
  #
25
25
  class ScatteredSetup < Cop
26
- MSG = 'Do not define multiple hooks in the same example group.'.freeze
26
+ MSG = 'Do not define multiple hooks in the same example group.'
27
27
 
28
28
  def on_block(node)
29
29
  return unless example_group?(node)
@@ -52,10 +52,10 @@ module RuboCop
52
52
  #
53
53
  class SharedContext < Cop
54
54
  MSG_EXAMPLES = "Use `shared_examples` when you don't "\
55
- 'define context.'.freeze
55
+ 'define context.'
56
56
 
57
57
  MSG_CONTEXT = "Use `shared_context` when you don't "\
58
- 'define examples.'.freeze
58
+ 'define examples.'
59
59
 
60
60
  examples = (Examples::ALL + Includes::EXAMPLES)
61
61
  def_node_search :examples?, examples.send_pattern
@@ -21,14 +21,14 @@ module RuboCop
21
21
  # include_examples 'foo bar baz'
22
22
  #
23
23
  class SharedExamples < Cop
24
- def_node_matcher :shared_examples, <<-PATTERN
25
- (send
26
- {(const nil? :RSpec) nil?}
27
- {#{(SharedGroups::ALL + Includes::ALL).node_pattern}} $sym ...)
28
- PATTERN
24
+ def_node_matcher :shared_examples,
25
+ (SharedGroups::ALL + Includes::ALL).send_pattern
29
26
 
30
27
  def on_send(node)
31
- shared_examples(node) do |ast_node|
28
+ shared_examples(node) do
29
+ ast_node = node.first_argument
30
+ next unless ast_node&.sym_type?
31
+
32
32
  checker = Checker.new(ast_node)
33
33
  add_offense(checker.node, message: checker.message)
34
34
  end
@@ -44,7 +44,7 @@ module RuboCop
44
44
  # :nodoc:
45
45
  class Checker
46
46
  MSG = 'Prefer %<prefer>s over `%<current>s` ' \
47
- 'to titleize shared examples.'.freeze
47
+ 'to titleize shared examples.'
48
48
 
49
49
  attr_reader :node
50
50
  def initialize(node)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -16,7 +18,7 @@ module RuboCop
16
18
  #
17
19
  class SingleArgumentMessageChain < Cop
18
20
  MSG = 'Use `%<recommended>s` instead of calling '\
19
- '`%<called>s` with a single argument.'.freeze
21
+ '`%<called>s` with a single argument.'
20
22
 
21
23
  def_node_matcher :message_chain, <<-PATTERN
22
24
  (send _ {:receive_message_chain :stub_chain} $_)
@@ -20,7 +20,7 @@ module RuboCop
20
20
  class SubjectStub < Cop
21
21
  include RuboCop::RSpec::TopLevelDescribe
22
22
 
23
- MSG = 'Do not stub your test subject.'.freeze
23
+ MSG = 'Do not stub your test subject.'
24
24
 
25
25
  # @!method subject(node)
26
26
  # Find a named or unnamed subject definition
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -29,9 +31,9 @@ module RuboCop
29
31
  #
30
32
  # expect { do_something }.not_to raise_error
31
33
  class UnspecifiedException < Cop
32
- MSG = 'Specify the exception being captured'.freeze
34
+ MSG = 'Specify the exception being captured'
33
35
 
34
- def_node_matcher :empty_raise_error_or_exception, <<-PATTERN.freeze
36
+ def_node_matcher :empty_raise_error_or_exception, <<-PATTERN
35
37
  (send
36
38
  (block
37
39
  (send nil? :expect) ...)
@@ -54,7 +56,7 @@ module RuboCop
54
56
  end
55
57
 
56
58
  def block_with_args?(node)
57
- return unless node && node.block_type?
59
+ return unless node&.block_type?
58
60
 
59
61
  node.arguments?
60
62
  end