rubocop-rspec 2.0.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/README.md +3 -3
- data/config/default.yml +141 -125
- data/lib/rubocop-rspec.rb +1 -0
- data/lib/rubocop/cop/rspec/any_instance.rb +6 -10
- data/lib/rubocop/cop/rspec/around_block.rb +3 -1
- data/lib/rubocop/cop/rspec/be.rb +2 -1
- data/lib/rubocop/cop/rspec/be_eql.rb +2 -0
- data/lib/rubocop/cop/rspec/before_after_all.rb +6 -3
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +5 -0
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -0
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +4 -0
- data/lib/rubocop/cop/rspec/context_method.rb +1 -0
- data/lib/rubocop/cop/rspec/context_wording.rb +7 -1
- data/lib/rubocop/cop/rspec/describe_class.rb +4 -1
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -1
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -0
- data/lib/rubocop/cop/rspec/described_class.rb +6 -1
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +2 -1
- data/lib/rubocop/cop/rspec/dialect.rb +1 -0
- data/lib/rubocop/cop/rspec/empty_hook.rb +1 -0
- data/lib/rubocop/cop/rspec/example_length.rb +26 -12
- data/lib/rubocop/cop/rspec/example_without_description.rb +1 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +1 -0
- data/lib/rubocop/cop/rspec/expect_actual.rb +2 -0
- data/lib/rubocop/cop/rspec/expect_change.rb +6 -3
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -0
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +3 -0
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +4 -0
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +2 -0
- data/lib/rubocop/cop/rspec/file_path.rb +31 -20
- data/lib/rubocop/cop/rspec/focus.rb +33 -1
- data/lib/rubocop/cop/rspec/hook_argument.rb +2 -0
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +1 -0
- data/lib/rubocop/cop/rspec/identical_equality_assertion.rb +38 -0
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +4 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -0
- data/lib/rubocop/cop/rspec/implicit_subject.rb +19 -1
- data/lib/rubocop/cop/rspec/instance_spy.rb +3 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +4 -0
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +3 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +3 -1
- data/lib/rubocop/cop/rspec/let_before_examples.rb +1 -0
- data/lib/rubocop/cop/rspec/let_setup.rb +3 -0
- data/lib/rubocop/cop/rspec/message_chain.rb +4 -10
- data/lib/rubocop/cop/rspec/message_expectation.rb +3 -0
- data/lib/rubocop/cop/rspec/message_spies.rb +4 -2
- data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
- data/lib/rubocop/cop/rspec/mixin/variable.rb +1 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +1 -2
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +3 -0
- data/lib/rubocop/cop/rspec/named_subject.rb +3 -0
- data/lib/rubocop/cop/rspec/not_to_not.rb +2 -0
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -0
- data/lib/rubocop/cop/rspec/pending.rb +4 -0
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +5 -0
- data/lib/rubocop/cop/rspec/rails/avoid_setup_hook.rb +44 -0
- data/lib/rubocop/cop/rspec/rails/http_status.rb +2 -0
- data/lib/rubocop/cop/rspec/receive_counts.rb +4 -0
- data/lib/rubocop/cop/rspec/receive_never.rb +2 -0
- data/lib/rubocop/cop/rspec/repeated_example_group_body.rb +8 -1
- data/lib/rubocop/cop/rspec/repeated_example_group_description.rb +4 -0
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -0
- data/lib/rubocop/cop/rspec/return_from_stub.rb +6 -0
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +6 -5
- data/lib/rubocop/cop/rspec/shared_examples.rb +1 -0
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +4 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -0
- data/lib/rubocop/cop/rspec/subject_stub.rb +15 -4
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -0
- data/lib/rubocop/cop/rspec/verified_doubles.rb +2 -0
- data/lib/rubocop/cop/rspec/void_expect.rb +3 -0
- data/lib/rubocop/cop/rspec/yield.rb +3 -0
- data/lib/rubocop/cop/rspec_cops.rb +2 -0
- data/lib/rubocop/rspec/config_formatter.rb +3 -1
- data/lib/rubocop/rspec/corrector/move_node.rb +6 -9
- data/lib/rubocop/rspec/example.rb +5 -0
- data/lib/rubocop/rspec/hook.rb +1 -0
- data/lib/rubocop/rspec/language.rb +10 -0
- data/lib/rubocop/rspec/node.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +9 -6
@@ -29,10 +29,12 @@ module RuboCop
|
|
29
29
|
|
30
30
|
MSG = 'Use a block to declare attribute values.'
|
31
31
|
|
32
|
+
# @!method value_matcher(node)
|
32
33
|
def_node_matcher :value_matcher, <<-PATTERN
|
33
34
|
(send _ !#reserved_method? $...)
|
34
35
|
PATTERN
|
35
36
|
|
37
|
+
# @!method factory_attributes(node)
|
36
38
|
def_node_matcher :factory_attributes, <<-PATTERN
|
37
39
|
(block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
|
38
40
|
PATTERN
|
@@ -79,6 +81,7 @@ module RuboCop
|
|
79
81
|
value_matcher(attribute).to_a.all?(&:block_pass_type?)
|
80
82
|
end
|
81
83
|
|
84
|
+
# @!method association?(node)
|
82
85
|
def_node_matcher :association?, '(hash <(pair (sym :factory) _) ...>)'
|
83
86
|
|
84
87
|
def autocorrect_replacing_parens(corrector, node)
|
@@ -30,7 +30,9 @@ module RuboCop
|
|
30
30
|
|
31
31
|
MSG_CREATE_LIST = 'Prefer create_list.'
|
32
32
|
MSG_N_TIMES = 'Prefer %<number>s.times.'
|
33
|
+
RESTRICT_ON_SEND = %i[create_list].freeze
|
33
34
|
|
35
|
+
# @!method n_times_block_without_arg?(node)
|
34
36
|
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
|
35
37
|
(block
|
36
38
|
(send (int _) :times)
|
@@ -39,10 +41,12 @@ module RuboCop
|
|
39
41
|
)
|
40
42
|
PATTERN
|
41
43
|
|
44
|
+
# @!method factory_call(node)
|
42
45
|
def_node_matcher :factory_call, <<-PATTERN
|
43
46
|
(send ${(const nil? {:FactoryGirl :FactoryBot}) nil?} :create (sym $_) $...)
|
44
47
|
PATTERN
|
45
48
|
|
49
|
+
# @!method factory_list_call(node)
|
46
50
|
def_node_matcher :factory_list_call, <<-PATTERN
|
47
51
|
(send {(const nil? {:FactoryGirl :FactoryBot}) nil?} :create_list (sym _) (int $_) ...)
|
48
52
|
PATTERN
|
@@ -25,7 +25,9 @@ module RuboCop
|
|
25
25
|
MSG = "Pass '%<class_name>s' string instead of `%<class_name>s` " \
|
26
26
|
'constant.'
|
27
27
|
ALLOWED_CONSTANTS = %w[Hash OpenStruct].freeze
|
28
|
+
RESTRICT_ON_SEND = %i[factory].freeze
|
28
29
|
|
30
|
+
# @!method class_name(node)
|
29
31
|
def_node_matcher :class_name, <<~PATTERN
|
30
32
|
(send _ :factory _ (hash <(pair (sym :class) $(const ...)) ...>))
|
31
33
|
PATTERN
|
@@ -61,51 +61,64 @@ module RuboCop
|
|
61
61
|
|
62
62
|
MSG = 'Spec path should end with `%<suffix>s`.'
|
63
63
|
|
64
|
-
|
64
|
+
# @!method example_group(node)
|
65
|
+
def_node_matcher :example_group, <<~PATTERN
|
65
66
|
(block
|
66
|
-
$(send #rspec? _example_group $
|
67
|
+
$(send #rspec? _example_group $_ $...) ...
|
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)
|
73
75
|
return unless top_level_groups.one?
|
74
76
|
|
75
|
-
|
77
|
+
example_group(node) do |send_node, example_group, arguments|
|
76
78
|
next if routing_spec?(arguments)
|
77
79
|
|
78
|
-
ensure_correct_file_path(send_node,
|
80
|
+
ensure_correct_file_path(send_node, example_group, arguments)
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
84
|
private
|
83
85
|
|
84
|
-
def ensure_correct_file_path(send_node,
|
85
|
-
|
86
|
-
return if filename_ends_with?(
|
86
|
+
def ensure_correct_file_path(send_node, example_group, arguments)
|
87
|
+
pattern = pattern_for(example_group, arguments.first)
|
88
|
+
return if filename_ends_with?(pattern)
|
87
89
|
|
88
|
-
|
90
|
+
# For the suffix shown in the offense message, modify the regular
|
91
|
+
# expression pattern to resemble a glob pattern for clearer error
|
92
|
+
# messages.
|
93
|
+
offense_suffix = pattern.gsub('.*', '*').sub('[^/]', '')
|
94
|
+
.sub('\.', '.')
|
95
|
+
add_offense(send_node, message: format(MSG, suffix: offense_suffix))
|
89
96
|
end
|
90
97
|
|
91
98
|
def routing_spec?(args)
|
92
99
|
args.any?(&method(:routing_metadata?))
|
93
100
|
end
|
94
101
|
|
95
|
-
def
|
96
|
-
|
102
|
+
def pattern_for(example_group, method_name)
|
103
|
+
if spec_suffix_only? || !example_group.const_type?
|
104
|
+
return pattern_for_spec_suffix_only?
|
105
|
+
end
|
97
106
|
|
98
|
-
|
107
|
+
[
|
108
|
+
expected_path(example_group),
|
109
|
+
name_pattern(method_name),
|
110
|
+
'[^/]*_spec\.rb'
|
111
|
+
].join
|
99
112
|
end
|
100
113
|
|
101
|
-
def
|
102
|
-
'
|
114
|
+
def pattern_for_spec_suffix_only?
|
115
|
+
'.*_spec\.rb'
|
103
116
|
end
|
104
117
|
|
105
|
-
def
|
118
|
+
def name_pattern(method_name)
|
106
119
|
return unless method_name&.str_type?
|
107
120
|
|
108
|
-
"
|
121
|
+
".*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
109
122
|
end
|
110
123
|
|
111
124
|
def expected_path(constant)
|
@@ -131,11 +144,9 @@ module RuboCop
|
|
131
144
|
cop_config['IgnoreMethods']
|
132
145
|
end
|
133
146
|
|
134
|
-
def filename_ends_with?(
|
135
|
-
filename =
|
136
|
-
|
137
|
-
.gsub('../', '')
|
138
|
-
File.fnmatch?("*#{glob}", filename)
|
147
|
+
def filename_ends_with?(pattern)
|
148
|
+
filename = File.expand_path(processed_source.buffer.name)
|
149
|
+
filename.match?("#{pattern}$")
|
139
150
|
end
|
140
151
|
|
141
152
|
def relevant_rubocop_rspec_file?(_file)
|
@@ -20,8 +20,12 @@ module RuboCop
|
|
20
20
|
# describe MyClass do
|
21
21
|
# end
|
22
22
|
class Focus < Base
|
23
|
+
extend AutoCorrector
|
24
|
+
include RangeHelp
|
25
|
+
|
23
26
|
MSG = 'Focused spec found.'
|
24
27
|
|
28
|
+
# @!method focusable_selector?(node)
|
25
29
|
def_node_matcher :focusable_selector?, <<-PATTERN
|
26
30
|
{
|
27
31
|
#ExampleGroups.regular
|
@@ -32,11 +36,13 @@ module RuboCop
|
|
32
36
|
}
|
33
37
|
PATTERN
|
34
38
|
|
39
|
+
# @!method metadata(node)
|
35
40
|
def_node_matcher :metadata, <<-PATTERN
|
36
41
|
{(send #rspec? #focusable_selector? <$(sym :focus) ...>)
|
37
42
|
(send #rspec? #focusable_selector? ... (hash <$(pair (sym :focus) true) ...>))}
|
38
43
|
PATTERN
|
39
44
|
|
45
|
+
# @!method focused_block?(node)
|
40
46
|
def_node_matcher :focused_block?,
|
41
47
|
send_pattern(<<~PATTERN)
|
42
48
|
{#ExampleGroups.focused #Examples.focused}
|
@@ -44,7 +50,13 @@ module RuboCop
|
|
44
50
|
|
45
51
|
def on_send(node)
|
46
52
|
focus_metadata(node) do |focus|
|
47
|
-
add_offense(focus)
|
53
|
+
add_offense(focus) do |corrector|
|
54
|
+
if focus.pair_type? || focus.str_type? || focus.sym_type?
|
55
|
+
corrector.remove(with_surrounding(focus))
|
56
|
+
elsif focus.send_type?
|
57
|
+
correct_send(corrector, focus)
|
58
|
+
end
|
59
|
+
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
@@ -55,6 +67,26 @@ module RuboCop
|
|
55
67
|
|
56
68
|
metadata(node, &block)
|
57
69
|
end
|
70
|
+
|
71
|
+
def with_surrounding(focus)
|
72
|
+
range_with_space = range_with_surrounding_space(
|
73
|
+
range: focus.loc.expression,
|
74
|
+
side: :left
|
75
|
+
)
|
76
|
+
|
77
|
+
range_with_surrounding_comma(range_with_space, :left)
|
78
|
+
end
|
79
|
+
|
80
|
+
def correct_send(corrector, focus)
|
81
|
+
range = focus.loc.selector
|
82
|
+
unfocused = focus.method_name.to_s.sub(/^f/, '')
|
83
|
+
unless Examples.regular(unfocused) || ExampleGroups.regular(unfocused)
|
84
|
+
return
|
85
|
+
end
|
86
|
+
|
87
|
+
corrector.replace(range,
|
88
|
+
range.source.sub(focus.method_name.to_s, unfocused))
|
89
|
+
end
|
58
90
|
end
|
59
91
|
end
|
60
92
|
end
|
@@ -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)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module RSpec
|
6
|
+
# Checks for equality assertions with identical expressions on both sides.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# expect(foo.bar).to eq(foo.bar)
|
12
|
+
# expect(foo.bar).to eql(foo.bar)
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# expect(foo.bar).to eq(2)
|
16
|
+
# expect(foo.bar).to eql(2)
|
17
|
+
#
|
18
|
+
class IdenticalEqualityAssertion < Base
|
19
|
+
MSG = 'Identical expressions on both sides of the equality ' \
|
20
|
+
'may indicate a flawed test.'
|
21
|
+
RESTRICT_ON_SEND = %i[to].freeze
|
22
|
+
|
23
|
+
# @!method equality_check?(node)
|
24
|
+
def_node_matcher :equality_check?, <<~PATTERN
|
25
|
+
(send (send nil? :expect $_) :to
|
26
|
+
{(send nil? {:eql :eq :be} $_)
|
27
|
+
(send (send nil? :be) :== $_)})
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
equality_check?(node) do |left, right|
|
32
|
+
add_offense(node) if left == right
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -18,7 +18,9 @@ module RuboCop
|
|
18
18
|
# end
|
19
19
|
class ImplicitBlockExpectation < Base
|
20
20
|
MSG = 'Avoid implicit block expectations.'
|
21
|
+
RESTRICT_ON_SEND = %i[is_expected should should_not].freeze
|
21
22
|
|
23
|
+
# @!method lambda?(node)
|
22
24
|
def_node_matcher :lambda?, <<-PATTERN
|
23
25
|
{
|
24
26
|
(send (const nil? :Proc) :new)
|
@@ -26,8 +28,10 @@ module RuboCop
|
|
26
28
|
}
|
27
29
|
PATTERN
|
28
30
|
|
31
|
+
# @!method lambda_subject?(node)
|
29
32
|
def_node_matcher :lambda_subject?, '(block #lambda? ...)'
|
30
33
|
|
34
|
+
# @!method implicit_expect(node)
|
31
35
|
def_node_matcher :implicit_expect, <<-PATTERN
|
32
36
|
$(send nil? {:is_expected :should :should_not} ...)
|
33
37
|
PATTERN
|
@@ -7,7 +7,7 @@ module RuboCop
|
|
7
7
|
#
|
8
8
|
# This cop can be configured using the `EnforcedStyle` option
|
9
9
|
#
|
10
|
-
# @example `EnforcedStyle: single_line_only`
|
10
|
+
# @example `EnforcedStyle: single_line_only` (default)
|
11
11
|
# # bad
|
12
12
|
# it do
|
13
13
|
# is_expected.to be_truthy
|
@@ -19,6 +19,22 @@ module RuboCop
|
|
19
19
|
# expect(subject).to be_truthy
|
20
20
|
# end
|
21
21
|
#
|
22
|
+
# @example `EnforcedStyle: single_statement_only`
|
23
|
+
# # bad
|
24
|
+
# it do
|
25
|
+
# foo = 1
|
26
|
+
# is_expected.to be_truthy
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# it do
|
31
|
+
# foo = 1
|
32
|
+
# expect(subject).to be_truthy
|
33
|
+
# end
|
34
|
+
# it do
|
35
|
+
# is_expected.to be_truthy
|
36
|
+
# end
|
37
|
+
#
|
22
38
|
# @example `EnforcedStyle: disallow`
|
23
39
|
# # bad
|
24
40
|
# it { is_expected.to be_truthy }
|
@@ -31,7 +47,9 @@ module RuboCop
|
|
31
47
|
include ConfigurableEnforcedStyle
|
32
48
|
|
33
49
|
MSG = "Don't use implicit subject."
|
50
|
+
RESTRICT_ON_SEND = %i[is_expected should should_not].freeze
|
34
51
|
|
52
|
+
# @!method implicit_subject?(node)
|
35
53
|
def_node_matcher :implicit_subject?, <<-PATTERN
|
36
54
|
(send nil? {:should :should_not :is_expected} ...)
|
37
55
|
PATTERN
|
@@ -21,9 +21,10 @@ module RuboCop
|
|
21
21
|
class InstanceSpy < Base
|
22
22
|
extend AutoCorrector
|
23
23
|
|
24
|
-
MSG = 'Use `instance_spy` when you check your double '\
|
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)
|
@@ -22,9 +22,11 @@ module RuboCop
|
|
22
22
|
extend AutoCorrector
|
23
23
|
include ConfigurableEnforcedStyle
|
24
24
|
|
25
|
-
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
|
25
|
+
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including ' \
|
26
26
|
'examples in a nested context.'
|
27
|
+
RESTRICT_ON_SEND = %i[it_behaves_like it_should_behave_like].freeze
|
27
28
|
|
29
|
+
# @!method example_inclusion_offense(node)
|
28
30
|
def_node_matcher :example_inclusion_offense, '(send _ % ...)'
|
29
31
|
|
30
32
|
def on_send(node)
|
@@ -17,8 +17,9 @@ module RuboCop
|
|
17
17
|
# end
|
18
18
|
class IteratedExpectation < Base
|
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
|
@@ -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)
|