rubocop-rspec 2.0.0.pre → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -2
  3. data/README.md +7 -3
  4. data/config/default.yml +159 -73
  5. data/lib/rubocop-rspec.rb +8 -8
  6. data/lib/rubocop/cop/rspec/align_left_let_brace.rb +7 -3
  7. data/lib/rubocop/cop/rspec/align_right_let_brace.rb +7 -3
  8. data/lib/rubocop/cop/rspec/any_instance.rb +6 -10
  9. data/lib/rubocop/cop/rspec/around_block.rb +3 -1
  10. data/lib/rubocop/cop/rspec/base.rb +6 -55
  11. data/lib/rubocop/cop/rspec/be.rb +3 -2
  12. data/lib/rubocop/cop/rspec/be_eql.rb +2 -0
  13. data/lib/rubocop/cop/rspec/before_after_all.rb +6 -3
  14. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +7 -2
  15. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +6 -2
  16. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +4 -0
  17. data/lib/rubocop/cop/rspec/context_method.rb +1 -0
  18. data/lib/rubocop/cop/rspec/context_wording.rb +7 -1
  19. data/lib/rubocop/cop/rspec/describe_class.rb +5 -2
  20. data/lib/rubocop/cop/rspec/describe_method.rb +3 -2
  21. data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -0
  22. data/lib/rubocop/cop/rspec/described_class.rb +6 -2
  23. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +3 -3
  24. data/lib/rubocop/cop/rspec/dialect.rb +2 -1
  25. data/lib/rubocop/cop/rspec/empty_example_group.rb +6 -45
  26. data/lib/rubocop/cop/rspec/empty_hook.rb +2 -1
  27. data/lib/rubocop/cop/rspec/empty_line_after_example.rb +1 -1
  28. data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
  29. data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
  30. data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
  31. data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +2 -2
  32. data/lib/rubocop/cop/rspec/example_length.rb +26 -12
  33. data/lib/rubocop/cop/rspec/example_without_description.rb +1 -0
  34. data/lib/rubocop/cop/rspec/example_wording.rb +1 -0
  35. data/lib/rubocop/cop/rspec/expect_actual.rb +3 -1
  36. data/lib/rubocop/cop/rspec/expect_change.rb +3 -0
  37. data/lib/rubocop/cop/rspec/expect_in_hook.rb +2 -1
  38. data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
  39. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
  40. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +4 -0
  41. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +2 -0
  42. data/lib/rubocop/cop/rspec/file_path.rb +26 -17
  43. data/lib/rubocop/cop/rspec/focus.rb +46 -8
  44. data/lib/rubocop/cop/rspec/hook_argument.rb +4 -4
  45. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +3 -2
  46. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +4 -0
  47. data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -1
  48. data/lib/rubocop/cop/rspec/implicit_subject.rb +2 -0
  49. data/lib/rubocop/cop/rspec/instance_spy.rb +3 -1
  50. data/lib/rubocop/cop/rspec/instance_variable.rb +5 -1
  51. data/lib/rubocop/cop/rspec/it_behaves_like.rb +3 -1
  52. data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
  53. data/lib/rubocop/cop/rspec/let_before_examples.rb +3 -2
  54. data/lib/rubocop/cop/rspec/let_setup.rb +10 -4
  55. data/lib/rubocop/cop/rspec/message_chain.rb +4 -10
  56. data/lib/rubocop/cop/rspec/message_expectation.rb +3 -0
  57. data/lib/rubocop/cop/rspec/message_spies.rb +5 -3
  58. data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
  59. data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +51 -0
  60. data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
  61. data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
  62. data/lib/rubocop/cop/rspec/mixin/variable.rb +21 -0
  63. data/lib/rubocop/cop/rspec/multiple_describes.rb +2 -3
  64. data/lib/rubocop/cop/rspec/multiple_expectations.rb +4 -1
  65. data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +3 -1
  66. data/lib/rubocop/cop/rspec/named_subject.rb +11 -12
  67. data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
  68. data/lib/rubocop/cop/rspec/not_to_not.rb +2 -0
  69. data/lib/rubocop/cop/rspec/overwriting_setup.rb +4 -1
  70. data/lib/rubocop/cop/rspec/pending.rb +17 -5
  71. data/lib/rubocop/cop/rspec/predicate_matcher.rb +8 -3
  72. data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -0
  73. data/lib/rubocop/cop/rspec/receive_counts.rb +4 -0
  74. data/lib/rubocop/cop/rspec/receive_never.rb +2 -0
  75. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
  76. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
  77. data/lib/rubocop/cop/rspec/repeated_include_example.rb +6 -2
  78. data/lib/rubocop/cop/rspec/return_from_stub.rb +6 -0
  79. data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
  80. data/lib/rubocop/cop/rspec/shared_context.rb +22 -11
  81. data/lib/rubocop/cop/rspec/shared_examples.rb +4 -1
  82. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +4 -1
  83. data/lib/rubocop/cop/rspec/stubbed_mock.rb +2 -1
  84. data/lib/rubocop/cop/rspec/subject_stub.rb +17 -6
  85. data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -0
  86. data/lib/rubocop/cop/rspec/variable_definition.rb +1 -1
  87. data/lib/rubocop/cop/rspec/variable_name.rb +1 -1
  88. data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -0
  89. data/lib/rubocop/cop/rspec/void_expect.rb +3 -0
  90. data/lib/rubocop/cop/rspec/yield.rb +3 -0
  91. data/lib/rubocop/cop/rspec_cops.rb +0 -1
  92. data/lib/rubocop/rspec/align_let_brace.rb +1 -1
  93. data/lib/rubocop/rspec/concept.rb +2 -2
  94. data/lib/rubocop/rspec/config_formatter.rb +5 -3
  95. data/lib/rubocop/rspec/corrector/move_node.rb +7 -10
  96. data/lib/rubocop/rspec/example.rb +5 -0
  97. data/lib/rubocop/rspec/example_group.rb +15 -5
  98. data/lib/rubocop/rspec/hook.rb +2 -1
  99. data/lib/rubocop/rspec/inject.rb +4 -2
  100. data/lib/rubocop/rspec/language.rb +159 -115
  101. data/lib/rubocop/rspec/language/node_pattern.rb +7 -24
  102. data/lib/rubocop/rspec/node.rb +1 -1
  103. data/lib/rubocop/rspec/version.rb +1 -1
  104. metadata +27 -16
  105. data/lib/rubocop/cop/rspec/cop.rb +0 -10
  106. data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +0 -41
  107. data/lib/rubocop/rspec.rb +0 -12
  108. data/lib/rubocop/rspec/empty_line_separation.rb +0 -48
  109. data/lib/rubocop/rspec/final_end_location.rb +0 -17
  110. data/lib/rubocop/rspec/top_level_describe.rb +0 -52
  111. data/lib/rubocop/rspec/top_level_group.rb +0 -57
  112. data/lib/rubocop/rspec/variable.rb +0 -16
data/lib/rubocop-rspec.rb CHANGED
@@ -5,26 +5,26 @@ require 'yaml'
5
5
 
6
6
  require 'rubocop'
7
7
 
8
- require_relative 'rubocop/rspec'
9
8
  require_relative 'rubocop/rspec/version'
10
9
  require_relative 'rubocop/rspec/inject'
11
10
  require_relative 'rubocop/rspec/node'
12
- require_relative 'rubocop/rspec/top_level_describe'
13
11
  require_relative 'rubocop/rspec/wording'
14
- require_relative 'rubocop/rspec/language'
15
12
  require_relative 'rubocop/rspec/language/node_pattern'
16
- require_relative 'rubocop/rspec/top_level_group'
13
+ require_relative 'rubocop/rspec/language'
14
+
15
+ require_relative 'rubocop/cop/rspec/mixin/top_level_group'
16
+ require_relative 'rubocop/cop/rspec/mixin/variable'
17
+ require_relative 'rubocop/cop/rspec/mixin/final_end_location'
18
+ require_relative 'rubocop/cop/rspec/mixin/comments_help'
19
+ require_relative 'rubocop/cop/rspec/mixin/empty_line_separation'
20
+
17
21
  require_relative 'rubocop/rspec/concept'
18
22
  require_relative 'rubocop/rspec/example_group'
19
23
  require_relative 'rubocop/rspec/example'
20
24
  require_relative 'rubocop/rspec/hook'
21
- require_relative 'rubocop/rspec/variable'
22
25
  require_relative 'rubocop/cop/rspec/base'
23
- require_relative 'rubocop/cop/rspec/cop'
24
26
  require_relative 'rubocop/rspec/align_let_brace'
25
27
  require_relative 'rubocop/rspec/factory_bot'
26
- require_relative 'rubocop/rspec/final_end_location'
27
- require_relative 'rubocop/rspec/empty_line_separation'
28
28
  require_relative 'rubocop/rspec/corrector/move_node'
29
29
 
30
30
  RuboCop::RSpec::Inject.defaults!
@@ -27,11 +27,9 @@ module RuboCop
27
27
  end
28
28
 
29
29
  def on_new_investigation
30
+ super
30
31
  return if processed_source.blank?
31
32
 
32
- token_aligner =
33
- RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
34
-
35
33
  token_aligner.offending_tokens.each do |let|
36
34
  add_offense(let.loc.begin) do |corrector|
37
35
  corrector.insert_before(
@@ -40,6 +38,12 @@ module RuboCop
40
38
  end
41
39
  end
42
40
  end
41
+
42
+ private
43
+
44
+ def token_aligner
45
+ RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :begin)
46
+ end
43
47
  end
44
48
  end
45
49
  end
@@ -27,11 +27,9 @@ module RuboCop
27
27
  end
28
28
 
29
29
  def on_new_investigation
30
+ super
30
31
  return if processed_source.blank?
31
32
 
32
- token_aligner =
33
- RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
34
-
35
33
  token_aligner.offending_tokens.each do |let|
36
34
  add_offense(let.loc.end) do |corrector|
37
35
  corrector.insert_before(
@@ -40,6 +38,12 @@ module RuboCop
40
38
  end
41
39
  end
42
40
  end
41
+
42
+ private
43
+
44
+ def token_aligner
45
+ RuboCop::RSpec::AlignLetBrace.new(processed_source.ast, :end)
46
+ end
43
47
  end
44
48
  end
45
49
  end
@@ -24,18 +24,14 @@ module RuboCop
24
24
  # end
25
25
  class AnyInstance < Base
26
26
  MSG = 'Avoid stubbing using `%<method>s`.'
27
-
28
- def_node_matcher :disallowed_stub, <<-PATTERN
29
- (send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)
30
- PATTERN
27
+ RESTRICT_ON_SEND = %i[
28
+ any_instance
29
+ allow_any_instance_of
30
+ expect_any_instance_of
31
+ ].freeze
31
32
 
32
33
  def on_send(node)
33
- disallowed_stub(node) do |method|
34
- add_offense(
35
- node,
36
- message: format(MSG, method: method)
37
- )
38
- end
34
+ add_offense(node, message: format(MSG, method: node.method_name))
39
35
  end
40
36
  end
41
37
  end
@@ -27,13 +27,15 @@ module RuboCop
27
27
  # end
28
28
  class AroundBlock < Base
29
29
  MSG_NO_ARG = 'Test object should be passed to around block.'
30
- MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
30
+ MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
31
31
  'or `%<arg>s.run`.'
32
32
 
33
+ # @!method hook(node)
33
34
  def_node_matcher :hook, <<-PATTERN
34
35
  (block (send nil? :around sym ?) (args $...) ...)
35
36
  PATTERN
36
37
 
38
+ # @!method find_arg_usage(node)
37
39
  def_node_search :find_arg_usage, <<-PATTERN
38
40
  {(send $... {:call :run}) (send _ _ $...) (yield $...) (block-pass $...)}
39
41
  PATTERN
@@ -4,30 +4,9 @@ module RuboCop
4
4
  module Cop
5
5
  module RSpec
6
6
  # @abstract parent class to RSpec cops
7
- #
8
- # The criteria for whether rubocop-rspec analyzes a certain ruby file
9
- # is configured via `AllCops/RSpec`. For example, if you want to
10
- # customize your project to scan all files within a `test/` directory
11
- # then you could add this to your configuration:
12
- #
13
- # @example configuring analyzed paths
14
- # # .rubocop.yml
15
- # # AllCops:
16
- # # RSpec:
17
- # # Patterns:
18
- # # - '_test.rb$'
19
- # # - '(?:^|/)test/'
20
7
  class Base < ::RuboCop::Cop::Base
21
8
  include RuboCop::RSpec::Language
22
- include RuboCop::RSpec::Language::NodePattern
23
-
24
- DEFAULT_CONFIGURATION =
25
- RuboCop::RSpec::CONFIG.fetch('AllCops').fetch('RSpec')
26
-
27
- DEFAULT_PATTERN_RE = Regexp.union(
28
- DEFAULT_CONFIGURATION.fetch('Patterns')
29
- .map(&Regexp.public_method(:new))
30
- )
9
+ extend RuboCop::RSpec::Language::NodePattern
31
10
 
32
11
  exclude_from_registry
33
12
 
@@ -36,39 +15,11 @@ module RuboCop
36
15
  RuboCop::Cop::Base.inherited(subclass)
37
16
  end
38
17
 
39
- def relevant_file?(file)
40
- relevant_rubocop_rspec_file?(file) && super
41
- end
42
-
43
- private
44
-
45
- def relevant_rubocop_rspec_file?(file)
46
- rspec_pattern.match?(file)
47
- end
48
-
49
- def rspec_pattern
50
- if rspec_pattern_config?
51
- Regexp.union(rspec_pattern_config.map(&Regexp.public_method(:new)))
52
- else
53
- DEFAULT_PATTERN_RE
54
- end
55
- end
56
-
57
- def all_cops_config
58
- config
59
- .for_all_cops
60
- end
61
-
62
- def rspec_pattern_config?
63
- return unless all_cops_config.key?('RSpec')
64
-
65
- all_cops_config.fetch('RSpec').key?('Patterns')
66
- end
67
-
68
- def rspec_pattern_config
69
- all_cops_config
70
- .fetch('RSpec', DEFAULT_CONFIGURATION)
71
- .fetch('Patterns')
18
+ # Set the config for dynamic DSL configuration-aware helpers
19
+ # that have no other means of accessing the configuration.
20
+ def on_new_investigation
21
+ super
22
+ RuboCop::RSpec::Language.config = config['RSpec']['Language']
72
23
  end
73
24
  end
74
25
  end
@@ -20,10 +20,11 @@ module RuboCop
20
20
  # expect(foo).to be(true)
21
21
  #
22
22
  class Be < Base
23
- MSG = 'Don\'t use `be` without an argument.'
23
+ MSG = "Don't use `be` without an argument."
24
24
 
25
+ # @!method be_without_args(node)
25
26
  def_node_matcher :be_without_args, <<-PATTERN
26
- (send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
27
+ (send _ #Runners.all $(send nil? :be))
27
28
  PATTERN
28
29
 
29
30
  def on_send(node)
@@ -39,7 +39,9 @@ module RuboCop
39
39
  extend AutoCorrector
40
40
 
41
41
  MSG = 'Prefer `be` over `eql`.'
42
+ RESTRICT_ON_SEND = %i[to].freeze
42
43
 
44
+ # @!method eql_type_with_identity(node)
43
45
  def_node_matcher :eql_type_with_identity, <<-PATTERN
44
46
  (send _ :to $(send nil? :eql {true false int float sym nil_type?}))
45
47
  PATTERN
@@ -24,11 +24,14 @@ module RuboCop
24
24
  # after(:each) { Widget.delete_all }
25
25
  # end
26
26
  class BeforeAfterAll < Base
27
- MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
28
- 'between tests. If you are using `rspec-rails`, and '\
29
- '`use_transactional_fixtures` is enabled, then records created '\
27
+ MSG = 'Beware of using `%<hook>s` as it may cause state to leak ' \
28
+ 'between tests. If you are using `rspec-rails`, and ' \
29
+ '`use_transactional_fixtures` is enabled, then records created ' \
30
30
  'in `%<hook>s` are not automatically rolled back.'
31
31
 
32
+ RESTRICT_ON_SEND = %i[before after].freeze
33
+
34
+ # @!method before_or_after_all(node)
32
35
  def_node_matcher :before_or_after_all, <<-PATTERN
33
36
  $(send _ {:before :after} (sym {:all :context}))
34
37
  PATTERN
@@ -30,20 +30,25 @@ module RuboCop
30
30
  'Capybara feature specs - instead, use the ' \
31
31
  '`have_current_path` matcher on `page`'
32
32
 
33
+ RESTRICT_ON_SEND = %i[expect].freeze
34
+
35
+ # @!method expectation_set_on_current_path(node)
33
36
  def_node_matcher :expectation_set_on_current_path, <<-PATTERN
34
37
  (send nil? :expect (send {(send nil? :page) nil?} :current_path))
35
38
  PATTERN
36
39
 
37
40
  # Supported matchers: eq(...) / match(/regexp/) / match('regexp')
41
+ # @!method as_is_matcher(node)
38
42
  def_node_matcher :as_is_matcher, <<-PATTERN
39
43
  (send
40
- #expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
44
+ #expectation_set_on_current_path $#Runners.all
41
45
  ${(send nil? :eq ...) (send nil? :match (regexp ...))})
42
46
  PATTERN
43
47
 
48
+ # @!method regexp_str_matcher(node)
44
49
  def_node_matcher :regexp_str_matcher, <<-PATTERN
45
50
  (send
46
- #expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
51
+ #expectation_set_on_current_path $#Runners.all
47
52
  $(send nil? :match (str $_)))
48
53
  PATTERN
49
54
 
@@ -55,15 +55,19 @@ module RuboCop
55
55
  feature: :describe
56
56
  }.freeze
57
57
 
58
- def_node_matcher :capybara_speak,
59
- SelectorSet.new(MAP.keys).node_pattern_union
58
+ # @!method capybara_speak(node)
59
+ def_node_matcher :capybara_speak, <<-PATTERN
60
+ {#{MAP.keys.map(&:inspect).join(' ')}}
61
+ PATTERN
60
62
 
63
+ # @!method spec?(node)
61
64
  def_node_matcher :spec?, <<-PATTERN
62
65
  (block
63
66
  (send #rspec? {:describe :feature} ...)
64
67
  ...)
65
68
  PATTERN
66
69
 
70
+ # @!method feature_method(node)
67
71
  def_node_matcher :feature_method, <<-PATTERN
68
72
  (block
69
73
  $(send #rspec? $#capybara_speak ...)
@@ -44,10 +44,14 @@ module RuboCop
44
44
  have_content
45
45
  ].freeze
46
46
 
47
+ RESTRICT_ON_SEND = CAPYBARA_MATCHER_METHODS
48
+
49
+ # @!method visible_true?(node)
47
50
  def_node_matcher :visible_true?, <<~PATTERN
48
51
  (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) true) ...>))
49
52
  PATTERN
50
53
 
54
+ # @!method visible_false?(node)
51
55
  def_node_matcher :visible_false?, <<~PATTERN
52
56
  (send nil? #capybara_matcher? ... (hash <$(pair (sym :visible) false) ...>))
53
57
  PATTERN
@@ -28,6 +28,7 @@ module RuboCop
28
28
 
29
29
  MSG = 'Use `describe` for testing methods.'
30
30
 
31
+ # @!method context_method(node)
31
32
  def_node_matcher :context_method, <<-PATTERN
32
33
  (block (send #rspec? :context $(str #method_name?) ...) ...)
33
34
  PATTERN
@@ -8,6 +8,7 @@ module RuboCop
8
8
  # The default list of prefixes is minimal. Users are encouraged to tailor
9
9
  # the configuration to meet project needs. Other acceptable prefixes may
10
10
  # include `if`, `unless`, `for`, `before`, `after`, or `during`.
11
+ # They may consist of multiple words if desired.
11
12
  #
12
13
  # @see https://rspec.rubystyle.guide/#context-descriptions
13
14
  # @see http://www.betterspecs.org/#contexts
@@ -37,6 +38,7 @@ module RuboCop
37
38
  class ContextWording < Base
38
39
  MSG = 'Start context description with %<prefixes>s.'
39
40
 
41
+ # @!method context_wording(node)
40
42
  def_node_matcher :context_wording, <<-PATTERN
41
43
  (block (send #rspec? { :context :shared_context } $(str #bad_prefix?) ...) ...)
42
44
  PATTERN
@@ -51,7 +53,7 @@ module RuboCop
51
53
  private
52
54
 
53
55
  def bad_prefix?(description)
54
- !prefixes.include?(description.split(/\b/).first)
56
+ !prefix_regex.match?(description)
55
57
  end
56
58
 
57
59
  def joined_prefixes
@@ -65,6 +67,10 @@ module RuboCop
65
67
  def prefixes
66
68
  cop_config['Prefixes'] || []
67
69
  end
70
+
71
+ def prefix_regex
72
+ /^#{Regexp.union(prefixes)}\b/
73
+ end
68
74
  end
69
75
  end
70
76
  end
@@ -35,19 +35,22 @@ module RuboCop
35
35
  # describe "A feature example", type: :feature do
36
36
  # end
37
37
  class DescribeClass < Base
38
- include RuboCop::RSpec::TopLevelGroup
38
+ include TopLevelGroup
39
39
 
40
- MSG = 'The first argument to describe should be '\
40
+ MSG = 'The first argument to describe should be ' \
41
41
  'the class or module being tested.'
42
42
 
43
+ # @!method example_group_with_ignored_metadata?(node)
43
44
  def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN
44
45
  (send #rspec? :describe ... (hash <#ignored_metadata? ...>))
45
46
  PATTERN
46
47
 
48
+ # @!method not_a_const_described(node)
47
49
  def_node_matcher :not_a_const_described, <<~PATTERN
48
50
  (send #rspec? :describe $[!const !#string_constant?] ...)
49
51
  PATTERN
50
52
 
53
+ # @!method sym_pair(node)
51
54
  def_node_matcher :sym_pair, <<~PATTERN
52
55
  (pair $sym $sym)
53
56
  PATTERN
@@ -17,11 +17,12 @@ module RuboCop
17
17
  # describe MyClass, '.my_class_method' do
18
18
  # end
19
19
  class DescribeMethod < Base
20
- include RuboCop::RSpec::TopLevelGroup
20
+ include TopLevelGroup
21
21
 
22
- MSG = 'The second argument to describe should be the method '\
22
+ MSG = 'The second argument to describe should be the method ' \
23
23
  "being tested. '#instance' or '.class'."
24
24
 
25
+ # @!method second_argument(node)
25
26
  def_node_matcher :second_argument, <<~PATTERN
26
27
  (block
27
28
  (send #rspec? :describe _first_argument $(str _) ...) ...
@@ -19,7 +19,9 @@ module RuboCop
19
19
  # @see https://github.com/rspec/rspec-core/issues/1610
20
20
  class DescribeSymbol < Base
21
21
  MSG = 'Avoid describing symbols.'
22
+ RESTRICT_ON_SEND = %i[describe].freeze
22
23
 
24
+ # @!method describe_symbol?(node)
23
25
  def_node_matcher :describe_symbol?, <<-PATTERN
24
26
  (send #rspec? :describe $sym ...)
25
27
  PATTERN
@@ -61,19 +61,23 @@ module RuboCop
61
61
  DESCRIBED_CLASS = 'described_class'
62
62
  MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
63
63
 
64
+ # @!method common_instance_exec_closure?(node)
64
65
  def_node_matcher :common_instance_exec_closure?, <<-PATTERN
65
66
  (block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
66
67
  PATTERN
67
68
 
68
- def_node_matcher :rspec_block?,
69
- RuboCop::RSpec::Language::ALL.block_pattern
69
+ # @!method rspec_block?(node)
70
+ def_node_matcher :rspec_block?, block_pattern('#ALL.all')
70
71
 
72
+ # @!method scope_changing_syntax?(node)
71
73
  def_node_matcher :scope_changing_syntax?, '{def class module}'
72
74
 
75
+ # @!method described_constant(node)
73
76
  def_node_matcher :described_constant, <<-PATTERN
74
77
  (block (send _ :describe $(const ...) ...) (args) $_)
75
78
  PATTERN
76
79
 
80
+ # @!method contains_described_class?(node)
77
81
  def_node_search :contains_described_class?, <<-PATTERN
78
82
  (send nil? :described_class)
79
83
  PATTERN