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
@@ -28,7 +28,7 @@ module RuboCop
28
28
  class ExampleLength < Cop
29
29
  include CodeLength
30
30
 
31
- MSG = 'Example has too many lines [%<total>d/%<max>d].'.freeze
31
+ MSG = 'Example has too many lines [%<total>d/%<max>d].'
32
32
 
33
33
  def on_block(node)
34
34
  return unless example?(node)
@@ -51,8 +51,8 @@ module RuboCop
51
51
  include ConfigurableEnforcedStyle
52
52
 
53
53
  MSG_DEFAULT_ARGUMENT = 'Omit the argument when you want to ' \
54
- 'have auto-generated description.'.freeze
55
- MSG_ADD_DESCRIPTION = 'Add a description.'.freeze
54
+ 'have auto-generated description.'
55
+ MSG_ADD_DESCRIPTION = 'Add a description.'
56
56
 
57
57
  def_node_matcher :example_description, '(send nil? _ $(str $_))'
58
58
 
@@ -30,8 +30,8 @@ module RuboCop
30
30
  # it 'does things' do
31
31
  # end
32
32
  class ExampleWording < Cop
33
- MSG_SHOULD = 'Do not use should when describing your tests.'.freeze
34
- MSG_IT = "Do not repeat 'it' when describing your tests.".freeze
33
+ MSG_SHOULD = 'Do not use should when describing your tests.'
34
+ MSG_IT = "Do not repeat 'it' when describing your tests."
35
35
 
36
36
  SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
37
37
  IT_PREFIX = /\Ait /i.freeze
@@ -17,7 +17,7 @@ module RuboCop
17
17
  # expect(name).to eq("John")
18
18
  #
19
19
  class ExpectActual < Cop
20
- MSG = 'Provide the actual you are testing to `expect(...)`.'.freeze
20
+ MSG = 'Provide the actual you are testing to `expect(...)`.'
21
21
 
22
22
  SIMPLE_LITERALS = %i[
23
23
  true
@@ -32,8 +32,8 @@ module RuboCop
32
32
  class ExpectChange < Cop
33
33
  include ConfigurableEnforcedStyle
34
34
 
35
- MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'.freeze
36
- MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'.freeze
35
+ MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
36
+ MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
37
37
 
38
38
  def_node_matcher :expect_change_with_arguments, <<-PATTERN
39
39
  (send nil? :change ({const send} nil? $_) (sym $_))
@@ -21,7 +21,7 @@ module RuboCop
21
21
  # expect(something).to eq 'foo'
22
22
  # end
23
23
  class ExpectInHook < Cop
24
- MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'.freeze
24
+ MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'
25
25
 
26
26
  def_node_search :expectation, Expectations::ALL.send_pattern
27
27
 
@@ -16,7 +16,7 @@ module RuboCop
16
16
  # expect { my_app.print_report }.to output('Hello World').to_stdout
17
17
  class ExpectOutput < Cop
18
18
  MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
19
- 'instead of mutating $%<name>s.'.freeze
19
+ 'instead of mutating $%<name>s.'
20
20
 
21
21
  def on_gvasgn(node)
22
22
  return unless inside_example_scope?(node)
@@ -25,53 +25,19 @@ module RuboCop
25
25
  # # good
26
26
  # count { 1 }
27
27
  class AttributeDefinedStatically < Cop
28
- MSG = 'Use a block to declare attribute values.'.freeze
29
-
30
- ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
31
-
32
- UNPROXIED_METHODS = %i[
33
- __send__
34
- __id__
35
- nil?
36
- send
37
- object_id
38
- extend
39
- instance_eval
40
- initialize
41
- block_given?
42
- raise
43
- caller
44
- method
45
- ].freeze
46
-
47
- DEFINITION_PROXY_METHODS = %i[
48
- add_attribute
49
- after
50
- association
51
- before
52
- callback
53
- ignore
54
- initialize_with
55
- sequence
56
- skip_create
57
- to_create
58
- ].freeze
59
-
60
- RESERVED_METHODS =
61
- DEFINITION_PROXY_METHODS +
62
- UNPROXIED_METHODS +
63
- ATTRIBUTE_DEFINING_METHODS
28
+ MSG = 'Use a block to declare attribute values.'
64
29
 
65
30
  def_node_matcher :value_matcher, <<-PATTERN
66
- (send {self nil?} !#reserved_method? $...)
31
+ (send _ !#reserved_method? $...)
67
32
  PATTERN
68
33
 
69
34
  def_node_search :factory_attributes, <<-PATTERN
70
- (block (send nil? #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
35
+ (block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
71
36
  PATTERN
72
37
 
73
38
  def on_block(node)
74
39
  factory_attributes(node).to_a.flatten.each do |attribute|
40
+ next unless offensive_receiver?(attribute.receiver, node)
75
41
  next if proc?(attribute) || association?(attribute)
76
42
 
77
43
  add_offense(attribute, location: :expression)
@@ -88,6 +54,20 @@ module RuboCop
88
54
 
89
55
  private
90
56
 
57
+ def offensive_receiver?(receiver, node)
58
+ receiver.nil? ||
59
+ receiver.self_type? ||
60
+ receiver_matches_first_block_argument?(receiver, node)
61
+ end
62
+
63
+ def receiver_matches_first_block_argument?(receiver, node)
64
+ first_block_argument = node.arguments.first
65
+
66
+ !first_block_argument.nil? &&
67
+ receiver.lvar_type? &&
68
+ receiver.node_parts == first_block_argument.node_parts
69
+ end
70
+
91
71
  def proc?(attribute)
92
72
  value_matcher(attribute).to_a.all?(&:block_pass_type?)
93
73
  end
@@ -134,11 +114,12 @@ module RuboCop
134
114
  end
135
115
 
136
116
  def reserved_method?(method_name)
137
- RESERVED_METHODS.include?(method_name)
117
+ RuboCop::RSpec::FactoryBot.reserved_methods.include?(method_name)
138
118
  end
139
119
 
140
120
  def attribute_defining_method?(method_name)
141
- ATTRIBUTE_DEFINING_METHODS.include?(method_name)
121
+ RuboCop::RSpec::FactoryBot.attribute_defining_methods
122
+ .include?(method_name)
142
123
  end
143
124
  end
144
125
  end
@@ -27,8 +27,8 @@ module RuboCop
27
27
  class CreateList < Cop
28
28
  include ConfigurableEnforcedStyle
29
29
 
30
- MSG_CREATE_LIST = 'Prefer create_list.'.freeze
31
- MSG_N_TIMES = 'Prefer %<number>s.times.'.freeze
30
+ MSG_CREATE_LIST = 'Prefer create_list.'
31
+ MSG_N_TIMES = 'Prefer %<number>s.times.'
32
32
 
33
33
  def_node_matcher :n_times_block_without_arg?, <<-PATTERN
34
34
  (block
@@ -44,7 +44,7 @@ module RuboCop
44
44
  class FilePath < Cop
45
45
  include RuboCop::RSpec::TopLevelDescribe
46
46
 
47
- MSG = 'Spec path should end with `%<suffix>s`.'.freeze
47
+ MSG = 'Spec path should end with `%<suffix>s`.'
48
48
 
49
49
  def_node_search :const_described?, '(send _ :describe (const ...) ...)'
50
50
  def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
@@ -75,7 +75,7 @@ module RuboCop
75
75
  end
76
76
 
77
77
  def name_glob(name)
78
- return unless name && name.str_type?
78
+ return unless name&.str_type?
79
79
 
80
80
  "*#{name.str_content.gsub(/\W/, '')}" unless ignore_methods?
81
81
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  # describe MyClass do
21
21
  # end
22
22
  class Focus < Cop
23
- MSG = 'Focused spec found.'.freeze
23
+ MSG = 'Focused spec found.'
24
24
 
25
25
  focusable =
26
26
  ExampleGroups::GROUPS +
@@ -36,8 +36,8 @@ module RuboCop
36
36
  FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
37
37
 
38
38
  def_node_matcher :metadata, <<-PATTERN
39
- {(send {(const nil? :RSpec) nil?} #{FOCUSABLE_SELECTORS} ... (hash $...))
40
- (send {(const nil? :RSpec) nil?} #{FOCUSABLE_SELECTORS} $...)}
39
+ {(send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (hash $...))
40
+ (send #{RSPEC} #{FOCUSABLE_SELECTORS} $...)}
41
41
  PATTERN
42
42
 
43
43
  def_node_matcher :focused_block?, focused.send_pattern
@@ -59,11 +59,10 @@ module RuboCop
59
59
  # end
60
60
  class HookArgument < Cop
61
61
  include ConfigurableEnforcedStyle
62
- include RangeHelp
63
62
 
64
63
  IMPLICIT_MSG = 'Omit the default `%<scope>p` ' \
65
- 'argument for RSpec hooks.'.freeze
66
- EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'.freeze
64
+ 'argument for RSpec hooks.'
65
+ EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
67
66
 
68
67
  HOOKS = Hooks::ALL.node_pattern_union.freeze
69
68
 
@@ -125,9 +124,8 @@ module RuboCop
125
124
  end
126
125
 
127
126
  def argument_range(send_node)
128
- range_between(
129
- send_node.loc.selector.end_pos,
130
- send_node.loc.expression.end_pos
127
+ send_node.loc.selector.end.with(
128
+ end_pos: send_node.loc.expression.end_pos
131
129
  )
132
130
  end
133
131
  end
@@ -27,7 +27,7 @@ module RuboCop
27
27
  include RangeHelp
28
28
  include RuboCop::RSpec::FinalEndLocation
29
29
 
30
- MSG = 'Move `%<hook>s` above the examples in the group.'.freeze
30
+ MSG = 'Move `%<hook>s` above the examples in the group.'
31
31
 
32
32
  def_node_matcher :example_or_group?, <<-PATTERN
33
33
  {
@@ -88,10 +88,7 @@ module RuboCop
88
88
  end
89
89
 
90
90
  def node_range(node)
91
- range_between(
92
- node.loc.expression.begin_pos,
93
- final_end_location(node).end_pos
94
- )
91
+ node.loc.expression.with(end_pos: final_end_location(node).end_pos)
95
92
  end
96
93
  end
97
94
  end
@@ -27,12 +27,12 @@ module RuboCop
27
27
  class ImplicitExpect < Cop
28
28
  include ConfigurableEnforcedStyle
29
29
 
30
- MSG = 'Prefer `%<good>s` over `%<bad>s`.'.freeze
30
+ MSG = 'Prefer `%<good>s` over `%<bad>s`.'
31
31
 
32
32
  def_node_matcher :implicit_expect, <<-PATTERN
33
33
  {
34
34
  (send nil? ${:should :should_not} ...)
35
- (send (send nil? $:is_expected) {:to :to_not :not_to} ...)
35
+ (send (send nil? $:is_expected) #{Runners::ALL.node_pattern_union} ...)
36
36
  }
37
37
  PATTERN
38
38
 
@@ -29,7 +29,7 @@ module RuboCop
29
29
  class ImplicitSubject < Cop
30
30
  include ConfigurableEnforcedStyle
31
31
 
32
- MSG = "Don't use implicit subject.".freeze
32
+ MSG = "Don't use implicit subject."
33
33
 
34
34
  def_node_matcher :implicit_subject?, <<-PATTERN
35
35
  (send nil? {:should :should_not :is_expected} ...)
@@ -20,7 +20,7 @@ module RuboCop
20
20
  #
21
21
  class InstanceSpy < Cop
22
22
  MSG = 'Use `instance_spy` when you check your double '\
23
- 'with `have_received`.'.freeze
23
+ 'with `have_received`.'
24
24
 
25
25
  def_node_search :null_double, <<-PATTERN
26
26
  (lvasgn $_
@@ -47,7 +47,7 @@ module RuboCop
47
47
  # end
48
48
  #
49
49
  class InstanceVariable < Cop
50
- MSG = 'Replace instance variable with local variable or `let`.'.freeze
50
+ MSG = 'Replace instance variable with local variable or `let`.'
51
51
 
52
52
  EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL
53
53
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -14,10 +16,10 @@ module RuboCop
14
16
  # # good
15
17
  # expect(foo).to be_something
16
18
  class InvalidPredicateMatcher < Cop
17
- MSG = 'Omit `?` from `%<matcher>s`.'.freeze
19
+ MSG = 'Omit `?` from `%<matcher>s`.'
18
20
 
19
21
  def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
20
- (send (send nil? :expect ...) {:to :not_to :to_not} $(send nil? #predicate?))
22
+ (send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
21
23
  PATTERN
22
24
 
23
25
  def on_send(node)
@@ -22,7 +22,7 @@ module RuboCop
22
22
  include ConfigurableEnforcedStyle
23
23
 
24
24
  MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
25
- 'examples in a nested context.'.freeze
25
+ 'examples in a nested context.'
26
26
 
27
27
  def_node_matcher :example_inclusion_offense, '(send _ % ...)'
28
28
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -15,7 +17,7 @@ module RuboCop
15
17
  # end
16
18
  class IteratedExpectation < Cop
17
19
  MSG = 'Prefer using the `all` matcher instead ' \
18
- 'of iterating over an array.'.freeze
20
+ 'of iterating over an array.'
19
21
 
20
22
  def_node_matcher :each?, <<-PATTERN
21
23
  (block
@@ -34,8 +34,7 @@ module RuboCop
34
34
  class LeadingSubject < Cop
35
35
  include RangeHelp
36
36
 
37
- MSG = 'Declare `subject` above any other `%<offending>s` ' \
38
- 'declarations.'.freeze
37
+ MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
39
38
 
40
39
  def on_block(node)
41
40
  return unless subject?(node) && !in_spec_block?(node)
@@ -34,7 +34,7 @@ module RuboCop
34
34
  include RangeHelp
35
35
  include RuboCop::RSpec::FinalEndLocation
36
36
 
37
- MSG = 'Move `let` before the examples in the group.'.freeze
37
+ MSG = 'Move `let` before the examples in the group.'
38
38
 
39
39
  def_node_matcher :example_or_group?, <<-PATTERN
40
40
  {
@@ -91,10 +91,7 @@ module RuboCop
91
91
  end
92
92
 
93
93
  def node_range(node)
94
- range_between(
95
- node.loc.expression.begin_pos,
96
- final_end_location(node).end_pos
97
- )
94
+ node.loc.expression.with(end_pos: final_end_location(node).end_pos)
98
95
  end
99
96
  end
100
97
  end
@@ -28,7 +28,7 @@ module RuboCop
28
28
  class LetSetup < Cop
29
29
  include RuboCop::RSpec::TopLevelDescribe
30
30
 
31
- MSG = 'Do not use `let!` for test setup.'.freeze
31
+ MSG = 'Do not use `let!` for test setup.'
32
32
 
33
33
  def_node_search :let_bang, <<-PATTERN
34
34
  (block $(send nil? :let! (sym $_)) args ...)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RuboCop
2
4
  module Cop
3
5
  module RSpec
@@ -12,7 +14,7 @@ module RuboCop
12
14
  # allow(foo).to receive(bar: thing)
13
15
  #
14
16
  class MessageChain < Cop
15
- MSG = 'Avoid stubbing using `%<method>s`.'.freeze
17
+ MSG = 'Avoid stubbing using `%<method>s`.'
16
18
 
17
19
  def_node_matcher :message_chain, <<-PATTERN
18
20
  (send _ {:receive_message_chain :stub_chain} ...)
@@ -27,7 +27,7 @@ module RuboCop
27
27
  class MessageExpectation < Cop
28
28
  include ConfigurableEnforcedStyle
29
29
 
30
- MSG = 'Prefer `%<style>s` for setting message expectations.'.freeze
30
+ MSG = 'Prefer `%<style>s` for setting message expectations.'
31
31
 
32
32
  SUPPORTED_STYLES = %w[allow expect].freeze
33
33
 
@@ -27,17 +27,16 @@ module RuboCop
27
27
  class MessageSpies < Cop
28
28
  include ConfigurableEnforcedStyle
29
29
 
30
- MSG_RECEIVE = 'Prefer `receive` for setting message '\
31
- 'expectations.'.freeze
30
+ MSG_RECEIVE = 'Prefer `receive` for setting message expectations.'
32
31
 
33
32
  MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\
34
33
  'expectations. Setup `%<source>s` as a spy using '\
35
- '`allow` or `instance_spy`.'.freeze
34
+ '`allow` or `instance_spy`.'
36
35
 
37
36
  SUPPORTED_STYLES = %w[have_received receive].freeze
38
37
 
39
38
  def_node_matcher :message_expectation, %(
40
- (send (send nil? :expect $_) {:to :to_not :not_to} ...)
39
+ (send (send nil? :expect $_) #{Runners::ALL.node_pattern_union} ...)
41
40
  )
42
41
 
43
42
  def_node_search :receive_message, %(