rubocop-rspec 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +2 -2
  4. data/config/default.yml +2 -0
  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 +5 -0
  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 +1 -0
  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 +1 -0
  24. data/lib/rubocop/cop/rspec/expect_actual.rb +1 -0
  25. data/lib/rubocop/cop/rspec/expect_change.rb +2 -0
  26. data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -0
  27. data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
  28. data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +3 -0
  29. data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -0
  30. data/lib/rubocop/cop/rspec/file_path.rb +2 -0
  31. data/lib/rubocop/cop/rspec/focus.rb +3 -0
  32. data/lib/rubocop/cop/rspec/hook_argument.rb +2 -0
  33. data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -0
  34. data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +3 -0
  35. data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -0
  36. data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -0
  37. data/lib/rubocop/cop/rspec/instance_spy.rb +2 -0
  38. data/lib/rubocop/cop/rspec/instance_variable.rb +4 -0
  39. data/lib/rubocop/cop/rspec/it_behaves_like.rb +1 -0
  40. data/lib/rubocop/cop/rspec/iterated_expectation.rb +2 -0
  41. data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -0
  42. data/lib/rubocop/cop/rspec/let_setup.rb +3 -0
  43. data/lib/rubocop/cop/rspec/message_expectation.rb +2 -0
  44. data/lib/rubocop/cop/rspec/message_spies.rb +2 -0
  45. data/lib/rubocop/cop/rspec/mixin/variable.rb +1 -0
  46. data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -0
  47. data/lib/rubocop/cop/rspec/named_subject.rb +3 -0
  48. data/lib/rubocop/cop/rspec/not_to_not.rb +1 -0
  49. data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -0
  50. data/lib/rubocop/cop/rspec/pending.rb +4 -0
  51. data/lib/rubocop/cop/rspec/predicate_matcher.rb +5 -0
  52. data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -0
  53. data/lib/rubocop/cop/rspec/receive_counts.rb +2 -0
  54. data/lib/rubocop/cop/rspec/receive_never.rb +1 -0
  55. data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
  56. data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
  57. data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -0
  58. data/lib/rubocop/cop/rspec/return_from_stub.rb +5 -0
  59. data/lib/rubocop/cop/rspec/shared_context.rb +4 -0
  60. data/lib/rubocop/cop/rspec/shared_examples.rb +1 -0
  61. data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +2 -0
  62. data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -0
  63. data/lib/rubocop/cop/rspec/subject_stub.rb +1 -0
  64. data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -0
  65. data/lib/rubocop/cop/rspec/verified_doubles.rb +1 -0
  66. data/lib/rubocop/cop/rspec/void_expect.rb +2 -0
  67. data/lib/rubocop/cop/rspec/yield.rb +3 -0
  68. data/lib/rubocop/rspec/example.rb +5 -0
  69. data/lib/rubocop/rspec/hook.rb +1 -0
  70. data/lib/rubocop/rspec/language.rb +10 -0
  71. data/lib/rubocop/rspec/version.rb +1 -1
  72. metadata +6 -6
@@ -27,6 +27,7 @@ module RuboCop
27
27
  ALLOWED_CONSTANTS = %w[Hash OpenStruct].freeze
28
28
  RESTRICT_ON_SEND = %i[factory].freeze
29
29
 
30
+ # @!method class_name(node)
30
31
  def_node_matcher :class_name, <<~PATTERN
31
32
  (send _ :factory _ (hash <(pair (sym :class) $(const ...)) ...>))
32
33
  PATTERN
@@ -61,12 +61,14 @@ module RuboCop
61
61
 
62
62
  MSG = 'Spec path should end with `%<suffix>s`.'
63
63
 
64
+ # @!method const_described(node)
64
65
  def_node_matcher :const_described, <<~PATTERN
65
66
  (block
66
67
  $(send #rspec? _example_group $(const ...) $...) ...
67
68
  )
68
69
  PATTERN
69
70
 
71
+ # @!method routing_metadata?(node)
70
72
  def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
71
73
 
72
74
  def on_top_level_example_group(node)
@@ -25,6 +25,7 @@ module RuboCop
25
25
 
26
26
  MSG = 'Focused spec found.'
27
27
 
28
+ # @!method focusable_selector?(node)
28
29
  def_node_matcher :focusable_selector?, <<-PATTERN
29
30
  {
30
31
  #ExampleGroups.regular
@@ -35,11 +36,13 @@ module RuboCop
35
36
  }
36
37
  PATTERN
37
38
 
39
+ # @!method metadata(node)
38
40
  def_node_matcher :metadata, <<-PATTERN
39
41
  {(send #rspec? #focusable_selector? <$(sym :focus) ...>)
40
42
  (send #rspec? #focusable_selector? ... (hash <$(pair (sym :focus) true) ...>))}
41
43
  PATTERN
42
44
 
45
+ # @!method focused_block?(node)
43
46
  def_node_matcher :focused_block?,
44
47
  send_pattern(<<~PATTERN)
45
48
  {#ExampleGroups.focused #Examples.focused}
@@ -64,10 +64,12 @@ module RuboCop
64
64
  IMPLICIT_MSG = 'Omit the default `%<scope>p` argument for RSpec hooks.'
65
65
  EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
66
66
 
67
+ # @!method scoped_hook(node)
67
68
  def_node_matcher :scoped_hook, <<-PATTERN
68
69
  (block $(send _ #Hooks.all (sym ${:each :example})) ...)
69
70
  PATTERN
70
71
 
72
+ # @!method unscoped_hook(node)
71
73
  def_node_matcher :unscoped_hook, '(block $(send _ #Hooks.all) ...)'
72
74
 
73
75
  def on_block(node)
@@ -28,6 +28,7 @@ module RuboCop
28
28
 
29
29
  MSG = 'Move `%<hook>s` above the examples in the group.'
30
30
 
31
+ # @!method example_or_group?(node)
31
32
  def_node_matcher :example_or_group?, <<-PATTERN
32
33
  {
33
34
  #{block_pattern('{#ExampleGroups.all #Examples.all}')}
@@ -20,6 +20,7 @@ module RuboCop
20
20
  MSG = 'Avoid implicit block expectations.'
21
21
  RESTRICT_ON_SEND = %i[is_expected should should_not].freeze
22
22
 
23
+ # @!method lambda?(node)
23
24
  def_node_matcher :lambda?, <<-PATTERN
24
25
  {
25
26
  (send (const nil? :Proc) :new)
@@ -27,8 +28,10 @@ module RuboCop
27
28
  }
28
29
  PATTERN
29
30
 
31
+ # @!method lambda_subject?(node)
30
32
  def_node_matcher :lambda_subject?, '(block #lambda? ...)'
31
33
 
34
+ # @!method implicit_expect(node)
32
35
  def_node_matcher :implicit_expect, <<-PATTERN
33
36
  $(send nil? {:is_expected :should :should_not} ...)
34
37
  PATTERN
@@ -30,6 +30,7 @@ module RuboCop
30
30
 
31
31
  MSG = 'Prefer `%<good>s` over `%<bad>s`.'
32
32
 
33
+ # @!method implicit_expect(node)
33
34
  def_node_matcher :implicit_expect, <<-PATTERN
34
35
  {
35
36
  (send nil? ${:should :should_not} ...)
@@ -33,6 +33,7 @@ module RuboCop
33
33
  MSG = "Don't use implicit subject."
34
34
  RESTRICT_ON_SEND = %i[is_expected should should_not].freeze
35
35
 
36
+ # @!method implicit_subject?(node)
36
37
  def_node_matcher :implicit_subject?, <<-PATTERN
37
38
  (send nil? {:should :should_not :is_expected} ...)
38
39
  PATTERN
@@ -24,6 +24,7 @@ module RuboCop
24
24
  MSG = 'Use `instance_spy` when you check your double ' \
25
25
  'with `have_received`.'
26
26
 
27
+ # @!method null_double(node)
27
28
  def_node_search :null_double, <<-PATTERN
28
29
  (lvasgn $_
29
30
  (send
@@ -31,6 +32,7 @@ module RuboCop
31
32
  ...) :as_null_object))
32
33
  PATTERN
33
34
 
35
+ # @!method have_received_usage(node)
34
36
  def_node_search :have_received_usage, <<-PATTERN
35
37
  (send
36
38
  (send nil? :expect
@@ -52,10 +52,12 @@ module RuboCop
52
52
  MSG = 'Avoid instance variables – use let, ' \
53
53
  'a method call, or a local variable (if possible).'
54
54
 
55
+ # @!method dynamic_class?(node)
55
56
  def_node_matcher :dynamic_class?, <<-PATTERN
56
57
  (block (send (const nil? :Class) :new ...) ...)
57
58
  PATTERN
58
59
 
60
+ # @!method custom_matcher?(node)
59
61
  def_node_matcher :custom_matcher?, <<-PATTERN
60
62
  (block {
61
63
  (send nil? :matcher sym)
@@ -63,8 +65,10 @@ module RuboCop
63
65
  } ...)
64
66
  PATTERN
65
67
 
68
+ # @!method ivar_usage(node)
66
69
  def_node_search :ivar_usage, '$(ivar $_)'
67
70
 
71
+ # @!method ivar_assigned?(node)
68
72
  def_node_search :ivar_assigned?, '(ivasgn % ...)'
69
73
 
70
74
  def on_top_level_group(node)
@@ -26,6 +26,7 @@ module RuboCop
26
26
  'examples in a nested context.'
27
27
  RESTRICT_ON_SEND = %i[it_behaves_like it_should_behave_like].freeze
28
28
 
29
+ # @!method example_inclusion_offense(node)
29
30
  def_node_matcher :example_inclusion_offense, '(send _ % ...)'
30
31
 
31
32
  def on_send(node)
@@ -19,6 +19,7 @@ module RuboCop
19
19
  MSG = 'Prefer using the `all` matcher instead ' \
20
20
  'of iterating over an array.'
21
21
 
22
+ # @!method each?(node)
22
23
  def_node_matcher :each?, <<-PATTERN
23
24
  (block
24
25
  (send ... :each)
@@ -27,6 +28,7 @@ module RuboCop
27
28
  )
28
29
  PATTERN
29
30
 
31
+ # @!method expectation?(node)
30
32
  def_node_matcher :expectation?, <<-PATTERN
31
33
  (send (send nil? :expect (lvar %)) :to ...)
32
34
  PATTERN
@@ -35,6 +35,7 @@ module RuboCop
35
35
 
36
36
  MSG = 'Move `let` before the examples in the group.'
37
37
 
38
+ # @!method example_or_group?(node)
38
39
  def_node_matcher :example_or_group?, <<-PATTERN
39
40
  {
40
41
  #{block_pattern('{#ExampleGroups.all #Examples.all}')}
@@ -28,6 +28,7 @@ module RuboCop
28
28
  class LetSetup < Base
29
29
  MSG = 'Do not use `let!` to setup objects not referenced in tests.'
30
30
 
31
+ # @!method example_or_shared_group_or_including?(node)
31
32
  def_node_matcher :example_or_shared_group_or_including?,
32
33
  block_pattern(<<~PATTERN)
33
34
  {
@@ -37,6 +38,7 @@ module RuboCop
37
38
  }
38
39
  PATTERN
39
40
 
41
+ # @!method let_bang(node)
40
42
  def_node_matcher :let_bang, <<-PATTERN
41
43
  {
42
44
  (block $(send nil? :let! {(sym $_) (str $_)}) ...)
@@ -44,6 +46,7 @@ module RuboCop
44
46
  }
45
47
  PATTERN
46
48
 
49
+ # @!method method_called?(node)
47
50
  def_node_search :method_called?, '(send nil? %)'
48
51
 
49
52
  def on_block(node)
@@ -32,10 +32,12 @@ module RuboCop
32
32
  SUPPORTED_STYLES = %w[allow expect].freeze
33
33
  RESTRICT_ON_SEND = %i[to].freeze
34
34
 
35
+ # @!method message_expectation(node)
35
36
  def_node_matcher :message_expectation, <<-PATTERN
36
37
  (send $(send nil? {:expect :allow} ...) :to #receive_message?)
37
38
  PATTERN
38
39
 
40
+ # @!method receive_message?(node)
39
41
  def_node_search :receive_message?, '(send nil? :receive ...)'
40
42
 
41
43
  def on_send(node)
@@ -35,10 +35,12 @@ module RuboCop
35
35
 
36
36
  SUPPORTED_STYLES = %w[have_received receive].freeze
37
37
 
38
+ # @!method message_expectation(node)
38
39
  def_node_matcher :message_expectation, %(
39
40
  (send (send nil? :expect $_) #Runners.all ...)
40
41
  )
41
42
 
43
+ # @!method receive_message(node)
42
44
  def_node_search :receive_message, %(
43
45
  $(send nil? {:receive :have_received} ...)
44
46
  )
@@ -10,6 +10,7 @@ module RuboCop
10
10
  Subjects = RuboCop::RSpec::Language::Subjects
11
11
  Helpers = RuboCop::RSpec::Language::Helpers
12
12
 
13
+ # @!method variable_definition?(node)
13
14
  def_node_matcher :variable_definition?, <<~PATTERN
14
15
  (send nil? {#Subjects.all #Helpers.all}
15
16
  $({sym str dsym dstr} ...) ...)
@@ -53,6 +53,7 @@ module RuboCop
53
53
  ANYTHING = ->(_node) { true }
54
54
  TRUE = ->(node) { node.true_type? }
55
55
 
56
+ # @!method aggregate_failures?(node)
56
57
  def_node_matcher :aggregate_failures?, <<-PATTERN
57
58
  (block {
58
59
  (send _ _ <(sym :aggregate_failures) ...>)
@@ -60,7 +61,9 @@ module RuboCop
60
61
  } ...)
61
62
  PATTERN
62
63
 
64
+ # @!method expect?(node)
63
65
  def_node_matcher :expect?, send_pattern('#Expectations.all')
66
+ # @!method aggregate_failures_block?(node)
64
67
  def_node_matcher :aggregate_failures_block?, <<-PATTERN
65
68
  (block (send nil? :aggregate_failures ...) ...)
66
69
  PATTERN
@@ -44,12 +44,15 @@ module RuboCop
44
44
  class NamedSubject < Base
45
45
  MSG = 'Name your test subject if you need to reference it explicitly.'
46
46
 
47
+ # @!method example_or_hook_block?(node)
47
48
  def_node_matcher :example_or_hook_block?,
48
49
  block_pattern('{#Examples.all #Hooks.all}')
49
50
 
51
+ # @!method shared_example?(node)
50
52
  def_node_matcher :shared_example?,
51
53
  block_pattern('#SharedGroups.examples')
52
54
 
55
+ # @!method subject_usage(node)
53
56
  def_node_search :subject_usage, '$(send nil? :subject)'
54
57
 
55
58
  def on_block(node)
@@ -22,6 +22,7 @@ module RuboCop
22
22
  MSG = 'Prefer `%<replacement>s` over `%<original>s`.'
23
23
  RESTRICT_ON_SEND = %i[not_to to_not].freeze
24
24
 
25
+ # @!method not_to_not_offense(node)
25
26
  def_node_matcher :not_to_not_offense, '(send _ % ...)'
26
27
 
27
28
  def on_send(node)
@@ -24,8 +24,10 @@ module RuboCop
24
24
  class OverwritingSetup < Base
25
25
  MSG = '`%<name>s` is already defined.'
26
26
 
27
+ # @!method setup?(node)
27
28
  def_node_matcher :setup?, block_pattern('{#Helpers.all #Subjects.all}')
28
29
 
30
+ # @!method first_argument_name(node)
29
31
  def_node_matcher :first_argument_name, '(send _ _ ({str sym} $_))'
30
32
 
31
33
  def on_block(node)
@@ -34,11 +34,13 @@ module RuboCop
34
34
  class Pending < Base
35
35
  MSG = 'Pending spec found.'
36
36
 
37
+ # @!method skippable?(node)
37
38
  def_node_matcher :skippable?,
38
39
  send_pattern(<<~PATTERN)
39
40
  {#ExampleGroups.regular #Examples.regular}
40
41
  PATTERN
41
42
 
43
+ # @!method skipped_in_metadata?(node)
42
44
  def_node_matcher :skipped_in_metadata?, <<-PATTERN
43
45
  {
44
46
  (send _ _ <#skip_or_pending? ...>)
@@ -46,8 +48,10 @@ module RuboCop
46
48
  }
47
49
  PATTERN
48
50
 
51
+ # @!method skip_or_pending?(node)
49
52
  def_node_matcher :skip_or_pending?, '{(sym :skip) (sym :pending)}'
50
53
 
54
+ # @!method pending_block?(node)
51
55
  def_node_matcher :pending_block?,
52
56
  send_pattern(<<~PATTERN)
53
57
  {
@@ -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
@@ -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)