rubocop-rspec 2.2.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -0
  3. data/README.md +3 -5
  4. data/config/default.yml +79 -3
  5. data/lib/rubocop/cop/rspec/around_block.rb +2 -0
  6. data/lib/rubocop/cop/rspec/be.rb +1 -0
  7. data/lib/rubocop/cop/rspec/be_eql.rb +1 -0
  8. data/lib/rubocop/cop/rspec/before_after_all.rb +1 -0
  9. data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +3 -0
  10. data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -0
  11. data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +2 -0
  12. data/lib/rubocop/cop/rspec/context_method.rb +1 -0
  13. data/lib/rubocop/cop/rspec/context_wording.rb +7 -1
  14. data/lib/rubocop/cop/rspec/describe_class.rb +3 -0
  15. data/lib/rubocop/cop/rspec/describe_method.rb +1 -0
  16. data/lib/rubocop/cop/rspec/describe_symbol.rb +1 -0
  17. data/lib/rubocop/cop/rspec/described_class.rb +6 -1
  18. data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +2 -1
  19. data/lib/rubocop/cop/rspec/dialect.rb +1 -0
  20. data/lib/rubocop/cop/rspec/empty_hook.rb +5 -1
  21. data/lib/rubocop/cop/rspec/example_length.rb +26 -12
  22. data/lib/rubocop/cop/rspec/example_without_description.rb +1 -0
  23. data/lib/rubocop/cop/rspec/example_wording.rb +4 -0
  24. data/lib/rubocop/cop/rspec/excessive_docstring_spacing.rb +100 -0
  25. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -0
  26. data/lib/rubocop/cop/rspec/expect_change.rb +5 -3
  27. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -0
  28. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
  29. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +3 -0
  30. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -0
  31. data/lib/rubocop/cop/rspec/file_path.rb +13 -9
  32. data/lib/rubocop/cop/rspec/focus.rb +3 -0
  33. data/lib/rubocop/cop/rspec/hook_argument.rb +3 -1
  34. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -0
  35. data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +38 -0
  36. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +3 -0
  37. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -0
  38. data/lib/rubocop/cop/rspec/implicit_subject.rb +18 -1
  39. data/lib/rubocop/cop/rspec/instance_spy.rb +2 -0
  40. data/lib/rubocop/cop/rspec/instance_variable.rb +4 -0
  41. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -0
  42. data/lib/rubocop/cop/rspec/iterated_expectation.rb +4 -0
  43. data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -0
  44. data/lib/rubocop/cop/rspec/let_setup.rb +3 -0
  45. data/lib/rubocop/cop/rspec/message_expectation.rb +2 -0
  46. data/lib/rubocop/cop/rspec/message_spies.rb +2 -0
  47. data/lib/rubocop/cop/rspec/mixin/variable.rb +1 -0
  48. data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -0
  49. data/lib/rubocop/cop/rspec/named_subject.rb +3 -0
  50. data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
  51. data/lib/rubocop/cop/rspec/not_to_not.rb +1 -0
  52. data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -0
  53. data/lib/rubocop/cop/rspec/pending.rb +4 -0
  54. data/lib/rubocop/cop/rspec/predicate_matcher.rb +5 -0
  55. data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +44 -0
  56. data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -0
  57. data/lib/rubocop/cop/rspec/receive_counts.rb +2 -0
  58. data/lib/rubocop/cop/rspec/receive_never.rb +1 -0
  59. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
  60. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
  61. data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -0
  62. data/lib/rubocop/cop/rspec/return_from_stub.rb +5 -0
  63. data/lib/rubocop/cop/rspec/shared_context.rb +4 -0
  64. data/lib/rubocop/cop/rspec/shared_examples.rb +1 -0
  65. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +2 -0
  66. data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -0
  67. data/lib/rubocop/cop/rspec/subject_declaration.rb +47 -0
  68. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -0
  69. data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -0
  70. data/lib/rubocop/cop/rspec/variable_definition.rb +19 -2
  71. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -0
  72. data/lib/rubocop/cop/rspec/void_expect.rb +2 -0
  73. data/lib/rubocop/cop/rspec/yield.rb +3 -0
  74. data/lib/rubocop/cop/rspec_cops.rb +4 -0
  75. data/lib/rubocop/rspec/align_let_brace.rb +2 -1
  76. data/lib/rubocop/rspec/config_formatter.rb +3 -0
  77. data/lib/rubocop/rspec/example.rb +5 -0
  78. data/lib/rubocop/rspec/hook.rb +1 -0
  79. data/lib/rubocop/rspec/language.rb +10 -0
  80. data/lib/rubocop/rspec/version.rb +1 -1
  81. metadata +17 -27
@@ -25,6 +25,7 @@ module RuboCop
25
25
  end
26
26
  end
27
27
 
28
+ # @!method predicate_in_actual?(node)
28
29
  def_node_matcher :predicate_in_actual?, <<-PATTERN
29
30
  (send
30
31
  (send nil? :expect {
@@ -34,10 +35,12 @@ module RuboCop
34
35
  $#boolean_matcher?)
35
36
  PATTERN
36
37
 
38
+ # @!method be_bool?(node)
37
39
  def_node_matcher :be_bool?, <<-PATTERN
38
40
  (send nil? {:be :eq :eql :equal} {true false})
39
41
  PATTERN
40
42
 
43
+ # @!method be_boolthy?(node)
41
44
  def_node_matcher :be_boolthy?, <<-PATTERN
42
45
  (send nil? {:be_truthy :be_falsey :be_falsy :a_truthy_value :a_falsey_value :a_falsy_value})
43
46
  PATTERN
@@ -152,6 +155,7 @@ module RuboCop
152
155
  end
153
156
  end
154
157
 
158
+ # @!method predicate_matcher?(node)
155
159
  def_node_matcher :predicate_matcher?, <<-PATTERN
156
160
  (send
157
161
  (send nil? :expect $!nil?)
@@ -160,6 +164,7 @@ module RuboCop
160
164
  (block $(send nil? #predicate_matcher_name? ...) ...)})
161
165
  PATTERN
162
166
 
167
+ # @!method predicate_matcher_block?(node)
163
168
  def_node_matcher :predicate_matcher_block?, <<-PATTERN
164
169
  (block
165
170
  (send
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ module Rails
7
+ # Checks that tests use RSpec `before` hook over Rails `setup` method.
8
+ #
9
+ # @example
10
+ #
11
+ # # bad
12
+ # setup do
13
+ # allow(foo).to receive(:bar)
14
+ # end
15
+ #
16
+ # # good
17
+ # before do
18
+ # allow(foo).to receive(:bar)
19
+ # end
20
+ #
21
+ class AvoidSetupHook < Base
22
+ extend AutoCorrector
23
+
24
+ MSG = 'Use `before` instead of `setup`.'
25
+
26
+ # @!method setup_call(node)
27
+ def_node_matcher :setup_call, <<-PATTERN
28
+ (block
29
+ $(send nil? :setup)
30
+ (args) _)
31
+ PATTERN
32
+
33
+ def on_block(node)
34
+ setup_call(node) do |setup|
35
+ add_offense(node) do |corrector|
36
+ corrector.replace setup, 'before'
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -35,6 +35,7 @@ module RuboCop
35
35
  include ConfigurableEnforcedStyle
36
36
  RESTRICT_ON_SEND = %i[have_http_status].freeze
37
37
 
38
+ # @!method http_status(node)
38
39
  def_node_matcher :http_status, <<-PATTERN
39
40
  (send nil? :have_http_status ${int sym})
40
41
  PATTERN
@@ -30,10 +30,12 @@ module RuboCop
30
30
 
31
31
  RESTRICT_ON_SEND = %i[times].freeze
32
32
 
33
+ # @!method receive_counts(node)
33
34
  def_node_matcher :receive_counts, <<-PATTERN
34
35
  (send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times)
35
36
  PATTERN
36
37
 
38
+ # @!method stub?(node)
37
39
  def_node_search :stub?, '(send nil? :receive ...)'
38
40
 
39
41
  def on_send(node)
@@ -18,6 +18,7 @@ module RuboCop
18
18
  MSG = 'Use `not_to receive` instead of `never`.'
19
19
  RESTRICT_ON_SEND = %i[never].freeze
20
20
 
21
+ # @!method method_on_stub?(node)
21
22
  def_node_search :method_on_stub?, '(send nil? :receive ...)'
22
23
 
23
24
  def on_send(node)
@@ -46,16 +46,23 @@ module RuboCop
46
46
  class RepeatedExampleGroupBody < Base
47
47
  MSG = 'Repeated %<group>s block body on line(s) %<loc>s'
48
48
 
49
+ # @!method several_example_groups?(node)
49
50
  def_node_matcher :several_example_groups?, <<-PATTERN
50
51
  (begin <#example_group_with_body? #example_group_with_body? ...>)
51
52
  PATTERN
52
53
 
54
+ # @!method metadata(node)
53
55
  def_node_matcher :metadata, '(block (send _ _ _ $...) ...)'
56
+
57
+ # @!method body(node)
54
58
  def_node_matcher :body, '(block _ args $...)'
59
+
60
+ # @!method const_arg(node)
55
61
  def_node_matcher :const_arg, '(block (send _ _ $const ...) ...)'
56
62
 
63
+ # @!method skip_or_pending?(node)
57
64
  def_node_matcher :skip_or_pending?, <<-PATTERN
58
- (block <(send nil? {:skip :pending}) ...>)
65
+ (block <(send nil? {:skip :pending} ...) ...>)
59
66
  PATTERN
60
67
 
61
68
  def on_begin(node)
@@ -46,18 +46,22 @@ module RuboCop
46
46
  class RepeatedExampleGroupDescription < Base
47
47
  MSG = 'Repeated %<group>s block description on line(s) %<loc>s'
48
48
 
49
+ # @!method several_example_groups?(node)
49
50
  def_node_matcher :several_example_groups?, <<-PATTERN
50
51
  (begin <#example_group? #example_group? ...>)
51
52
  PATTERN
52
53
 
54
+ # @!method doc_string_and_metadata(node)
53
55
  def_node_matcher :doc_string_and_metadata, <<-PATTERN
54
56
  (block (send _ _ $_ $...) ...)
55
57
  PATTERN
56
58
 
59
+ # @!method skip_or_pending?(node)
57
60
  def_node_matcher :skip_or_pending?, <<-PATTERN
58
61
  (block <(send nil? {:skip :pending}) ...>)
59
62
  PATTERN
60
63
 
64
+ # @!method empty_description?(node)
61
65
  def_node_matcher :empty_description?, '(block (send _ _) ...)'
62
66
 
63
67
  def on_begin(node)
@@ -50,13 +50,16 @@ module RuboCop
50
50
  MSG = 'Repeated include of shared_examples %<name>s ' \
51
51
  'on line(s) %<repeat>s'
52
52
 
53
+ # @!method several_include_examples?(node)
53
54
  def_node_matcher :several_include_examples?, <<-PATTERN
54
55
  (begin <#include_examples? #include_examples? ...>)
55
56
  PATTERN
56
57
 
58
+ # @!method include_examples?(node)
57
59
  def_node_matcher :include_examples?,
58
60
  send_pattern('#Includes.examples')
59
61
 
62
+ # @!method shared_examples_name(node)
60
63
  def_node_matcher :shared_examples_name, <<-PATTERN
61
64
  (send _ #Includes.examples $_ ...)
62
65
  PATTERN
@@ -41,8 +41,13 @@ module RuboCop
41
41
  MSG_BLOCK = 'Use block for static values.'
42
42
  RESTRICT_ON_SEND = %i[and_return].freeze
43
43
 
44
+ # @!method contains_stub?(node)
44
45
  def_node_search :contains_stub?, '(send nil? :receive (...))'
46
+
47
+ # @!method stub_with_block?(node)
45
48
  def_node_matcher :stub_with_block?, '(block #contains_stub? ...)'
49
+
50
+ # @!method and_return_value(node)
46
51
  def_node_search :and_return_value, <<-PATTERN
47
52
  $(send _ :and_return $(...))
48
53
  PATTERN
@@ -56,9 +56,11 @@ module RuboCop
56
56
  MSG_EXAMPLES = "Use `shared_examples` when you don't define context."
57
57
  MSG_CONTEXT = "Use `shared_context` when you don't define examples."
58
58
 
59
+ # @!method examples?(node)
59
60
  def_node_search :examples?,
60
61
  send_pattern('{#Includes.examples #Examples.all}')
61
62
 
63
+ # @!method context?(node)
62
64
  def_node_search :context?, <<-PATTERN
63
65
  (
64
66
  send #rspec? {
@@ -70,8 +72,10 @@ module RuboCop
70
72
  )
71
73
  PATTERN
72
74
 
75
+ # @!method shared_context(node)
73
76
  def_node_matcher :shared_context,
74
77
  block_pattern('#SharedGroups.context')
78
+ # @!method shared_example(node)
75
79
  def_node_matcher :shared_example,
76
80
  block_pattern('#SharedGroups.examples')
77
81
 
@@ -23,6 +23,7 @@ module RuboCop
23
23
  class SharedExamples < Base
24
24
  extend AutoCorrector
25
25
 
26
+ # @!method shared_examples(node)
26
27
  def_node_matcher :shared_examples,
27
28
  send_pattern(
28
29
  '{#SharedGroups.all #Includes.all}'
@@ -23,10 +23,12 @@ module RuboCop
23
23
  '`%<called>s` with a single argument.'
24
24
  RESTRICT_ON_SEND = %i[receive_message_chain stub_chain].freeze
25
25
 
26
+ # @!method message_chain(node)
26
27
  def_node_matcher :message_chain, <<-PATTERN
27
28
  (send _ {:receive_message_chain :stub_chain} $_)
28
29
  PATTERN
29
30
 
31
+ # @!method single_key_hash?(node)
30
32
  def_node_matcher :single_key_hash?, '(hash pair)'
31
33
 
32
34
  def on_send(node)
@@ -39,6 +39,7 @@ module RuboCop
39
39
  }
40
40
  PATTERN
41
41
 
42
+ # @!method configured_response?(node)
42
43
  def_node_matcher :configured_response?, <<~PATTERN
43
44
  { :and_return :and_raise :and_throw :and_yield
44
45
  :and_call_original :and_wrap_original }
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ # Ensure that subject is defined using subject helper.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ # let(:subject) { foo }
12
+ # let!(:subject) { foo }
13
+ # subject(:subject) { foo }
14
+ # subject!(:subject) { foo }
15
+ #
16
+ # # bad
17
+ # block = -> {}
18
+ # let(:subject, &block)
19
+ #
20
+ # # good
21
+ # subject(:test_subject) { foo }
22
+ #
23
+ class SubjectDeclaration < Base
24
+ MSG_LET = 'Use subject explicitly rather than using let'
25
+ MSG_REDUNDANT = 'Ambiguous declaration of subject'
26
+
27
+ # @!method offensive_subject_declaration?(node)
28
+ def_node_matcher :offensive_subject_declaration?, <<~PATTERN
29
+ (send nil? ${#Subjects.all #Helpers.all} {(sym :subject) (str "subject")} ...)
30
+ PATTERN
31
+
32
+ def on_send(node)
33
+ offense = offensive_subject_declaration?(node)
34
+ return unless offense
35
+
36
+ add_offense(node, message: message_for(offense))
37
+ end
38
+
39
+ private
40
+
41
+ def message_for(offense)
42
+ Helpers.all(offense) ? MSG_LET : MSG_REDUNDANT
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -81,6 +81,7 @@ module RuboCop
81
81
  )
82
82
  PATTERN
83
83
 
84
+ # @!method message_expectation_matcher?(node)
84
85
  def_node_search :message_expectation_matcher?, <<-PATTERN
85
86
  (send nil? {
86
87
  :receive :receive_messages :receive_message_chain :have_received
@@ -34,6 +34,7 @@ module RuboCop
34
34
  MSG = 'Specify the exception being captured'
35
35
  RESTRICT_ON_SEND = %i[to].freeze
36
36
 
37
+ # @!method empty_raise_error_or_exception(node)
37
38
  def_node_matcher :empty_raise_error_or_exception, <<-PATTERN
38
39
  (send
39
40
  (block
@@ -23,6 +23,7 @@ module RuboCop
23
23
  # subject('user') { create_user }
24
24
  # let('user_name') { 'Adam' }
25
25
  class VariableDefinition < Base
26
+ extend AutoCorrector
26
27
  include ConfigurableEnforcedStyle
27
28
  include Variable
28
29
 
@@ -30,14 +31,30 @@ module RuboCop
30
31
 
31
32
  def on_send(node)
32
33
  variable_definition?(node) do |variable|
33
- if style_violation?(variable)
34
- add_offense(variable, message: format(MSG, style: style))
34
+ next unless style_violation?(variable)
35
+
36
+ add_offense(
37
+ variable,
38
+ message: format(MSG, style: style)
39
+ ) do |corrector|
40
+ corrector.replace(variable, correct_variable(variable))
35
41
  end
36
42
  end
37
43
  end
38
44
 
39
45
  private
40
46
 
47
+ def correct_variable(variable)
48
+ case variable.type
49
+ when :dsym
50
+ variable.source[1..-1]
51
+ when :sym
52
+ variable.value.to_s.inspect
53
+ else
54
+ variable.value.to_sym.inspect
55
+ end
56
+ end
57
+
41
58
  def style_violation?(variable)
42
59
  style == :symbols && string?(variable) ||
43
60
  style == :strings && symbol?(variable)
@@ -26,6 +26,7 @@ module RuboCop
26
26
  MSG = 'Prefer using verifying doubles over normal doubles.'
27
27
  RESTRICT_ON_SEND = %i[double spy].freeze
28
28
 
29
+ # @!method unverified_double(node)
29
30
  def_node_matcher :unverified_double, <<-PATTERN
30
31
  {(send nil? {:double :spy} $...)}
31
32
  PATTERN
@@ -16,10 +16,12 @@ module RuboCop
16
16
  'Chain the methods or remove it.'
17
17
  RESTRICT_ON_SEND = %i[expect].freeze
18
18
 
19
+ # @!method expect?(node)
19
20
  def_node_matcher :expect?, <<-PATTERN
20
21
  (send nil? :expect ...)
21
22
  PATTERN
22
23
 
24
+ # @!method expect_block?(node)
23
25
  def_node_matcher :expect_block?, <<-PATTERN
24
26
  (block #expect? (args) _body)
25
27
  PATTERN
@@ -17,10 +17,13 @@ module RuboCop
17
17
 
18
18
  MSG = 'Use `.and_yield`.'
19
19
 
20
+ # @!method method_on_stub?(node)
20
21
  def_node_search :method_on_stub?, '(send nil? :receive ...)'
21
22
 
23
+ # @!method block_arg(node)
22
24
  def_node_matcher :block_arg, '(args (blockarg $_))'
23
25
 
26
+ # @!method block_call?(node)
24
27
  def_node_matcher :block_call?, '(send (lvar %) :call ...)'
25
28
 
26
29
  def on_block(node)
@@ -8,6 +8,7 @@ require_relative 'rspec/factory_bot/attribute_defined_statically'
8
8
  require_relative 'rspec/factory_bot/create_list'
9
9
  require_relative 'rspec/factory_bot/factory_class_name'
10
10
 
11
+ require_relative 'rspec/rails/avoid_setup_hook'
11
12
  begin
12
13
  require_relative 'rspec/rails/http_status'
13
14
  rescue LoadError
@@ -39,6 +40,7 @@ require_relative 'rspec/empty_line_after_subject'
39
40
  require_relative 'rspec/example_length'
40
41
  require_relative 'rspec/example_without_description'
41
42
  require_relative 'rspec/example_wording'
43
+ require_relative 'rspec/excessive_docstring_spacing'
42
44
  require_relative 'rspec/expect_actual'
43
45
  require_relative 'rspec/expect_change'
44
46
  require_relative 'rspec/expect_in_hook'
@@ -47,6 +49,7 @@ require_relative 'rspec/file_path'
47
49
  require_relative 'rspec/focus'
48
50
  require_relative 'rspec/hook_argument'
49
51
  require_relative 'rspec/hooks_before_examples'
52
+ require_relative 'rspec/identical_equality_assertion'
50
53
  require_relative 'rspec/implicit_block_expectation'
51
54
  require_relative 'rspec/implicit_expect'
52
55
  require_relative 'rspec/implicit_subject'
@@ -86,6 +89,7 @@ require_relative 'rspec/shared_context'
86
89
  require_relative 'rspec/shared_examples'
87
90
  require_relative 'rspec/single_argument_message_chain'
88
91
  require_relative 'rspec/stubbed_mock'
92
+ require_relative 'rspec/subject_declaration'
89
93
  require_relative 'rspec/subject_stub'
90
94
  require_relative 'rspec/unspecified_exception'
91
95
  require_relative 'rspec/variable_definition'
@@ -5,6 +5,7 @@ module RuboCop
5
5
  # Shared behavior for aligning braces for single line lets
6
6
  class AlignLetBrace
7
7
  include RuboCop::RSpec::Language
8
+ include RuboCop::Cop::Util
8
9
 
9
10
  def initialize(root, token)
10
11
  @root = root
@@ -34,7 +35,7 @@ module RuboCop
34
35
  def let_group_for(let)
35
36
  adjacent_let_chunks.detect do |chunk|
36
37
  chunk.any? do |member|
37
- member == let && member.loc.line == let.loc.line
38
+ member == let && same_line?(member, let)
38
39
  end
39
40
  end
40
41
  end
@@ -7,6 +7,7 @@ module RuboCop
7
7
  # Builds a YAML config file from two config hashes
8
8
  class ConfigFormatter
9
9
  EXTENSION_ROOT_DEPARTMENT = %r{^(RSpec/)}.freeze
10
+ SUBDEPARTMENTS = %(RSpec/Capybara RSpec/FactoryBot RSpec/Rails)
10
11
  STYLE_GUIDE_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'
11
12
 
12
13
  def initialize(config, descriptions)
@@ -24,6 +25,8 @@ module RuboCop
24
25
 
25
26
  def unified_config
26
27
  cops.each_with_object(config.dup) do |cop, unified|
28
+ next if SUBDEPARTMENTS.include?(cop)
29
+
27
30
  unified[cop] = config.fetch(cop)
28
31
  .merge(descriptions.fetch(cop))
29
32
  .merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
@@ -4,8 +4,13 @@ module RuboCop
4
4
  module RSpec
5
5
  # Wrapper for RSpec examples
6
6
  class Example < Concept
7
+ # @!method extract_doc_string(node)
7
8
  def_node_matcher :extract_doc_string, '(send _ _ $_ ...)'
9
+
10
+ # @!method extract_metadata(node)
8
11
  def_node_matcher :extract_metadata, '(send _ _ _ $...)'
12
+
13
+ # @!method extract_implementation(node)
9
14
  def_node_matcher :extract_implementation, '(block send args $_)'
10
15
 
11
16
  def doc_string
@@ -4,6 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Wrapper for RSpec hook
6
6
  class Hook < Concept
7
+ # @!method extract_metadata(node)
7
8
  def_node_matcher :extract_metadata, <<~PATTERN
8
9
  (block
9
10
  (send _ _ #valid_scope? ? $...) ...
@@ -19,23 +19,31 @@ module RuboCop
19
19
  attr_accessor :config
20
20
  end
21
21
 
22
+ # @!method rspec?(node)
22
23
  def_node_matcher :rspec?, '{(const {nil? cbase} :RSpec) nil?}'
23
24
 
25
+ # @!method example_group?(node)
24
26
  def_node_matcher :example_group?, block_pattern('#ExampleGroups.all')
25
27
 
28
+ # @!method shared_group?(node)
26
29
  def_node_matcher :shared_group?, block_pattern('#SharedGroups.all')
27
30
 
31
+ # @!method spec_group?(node)
28
32
  def_node_matcher :spec_group?,
29
33
  block_pattern('{#SharedGroups.all #ExampleGroups.all}')
30
34
 
35
+ # @!method example_group_with_body?(node)
31
36
  def_node_matcher :example_group_with_body?, <<-PATTERN
32
37
  (block #{send_pattern('#ExampleGroups.all')} args !nil?)
33
38
  PATTERN
34
39
 
40
+ # @!method example?(node)
35
41
  def_node_matcher :example?, block_pattern('#Examples.all')
36
42
 
43
+ # @!method hook?(node)
37
44
  def_node_matcher :hook?, block_pattern('#Hooks.all')
38
45
 
46
+ # @!method let?(node)
39
47
  def_node_matcher :let?, <<-PATTERN
40
48
  {
41
49
  #{block_pattern('#Helpers.all')}
@@ -43,6 +51,7 @@ module RuboCop
43
51
  }
44
52
  PATTERN
45
53
 
54
+ # @!method include?(node)
46
55
  def_node_matcher :include?, <<-PATTERN
47
56
  {
48
57
  #{send_pattern('#Includes.all')}
@@ -50,6 +59,7 @@ module RuboCop
50
59
  }
51
60
  PATTERN
52
61
 
62
+ # @!method subject?(node)
53
63
  def_node_matcher :subject?, block_pattern('#Subjects.all')
54
64
 
55
65
  module ExampleGroups # :nodoc:
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module RSpec
5
5
  # Version information for the RSpec RuboCop plugin.
6
6
  module Version
7
- STRING = '2.2.0'
7
+ STRING = '2.6.0'
8
8
  end
9
9
  end
10
10
  end