rubocop-rspec 2.0.0.pre → 2.3.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 -2
- data/README.md +7 -3
- data/config/default.yml +159 -73
- data/lib/rubocop-rspec.rb +8 -8
- data/lib/rubocop/cop/rspec/align_left_let_brace.rb +7 -3
- data/lib/rubocop/cop/rspec/align_right_let_brace.rb +7 -3
- 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/base.rb +6 -55
- data/lib/rubocop/cop/rspec/be.rb +3 -2
- 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 +7 -2
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +6 -2
- 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 +5 -2
- data/lib/rubocop/cop/rspec/describe_method.rb +3 -2
- data/lib/rubocop/cop/rspec/describe_symbol.rb +2 -0
- data/lib/rubocop/cop/rspec/described_class.rb +6 -2
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +3 -3
- data/lib/rubocop/cop/rspec/dialect.rb +2 -1
- data/lib/rubocop/cop/rspec/empty_example_group.rb +6 -45
- data/lib/rubocop/cop/rspec/empty_hook.rb +2 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example_group.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_final_let.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_line_after_subject.rb +2 -2
- 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 +3 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +3 -0
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +2 -1
- 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 +26 -17
- data/lib/rubocop/cop/rspec/focus.rb +46 -8
- data/lib/rubocop/cop/rspec/hook_argument.rb +4 -4
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +3 -2
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +4 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +2 -1
- data/lib/rubocop/cop/rspec/implicit_subject.rb +2 -0
- data/lib/rubocop/cop/rspec/instance_spy.rb +3 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +5 -1
- 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 +3 -2
- data/lib/rubocop/cop/rspec/let_setup.rb +10 -4
- 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 +5 -3
- data/lib/rubocop/cop/rspec/mixin/comments_help.rb +38 -0
- data/lib/rubocop/cop/rspec/mixin/empty_line_separation.rb +51 -0
- data/lib/rubocop/cop/rspec/mixin/final_end_location.rb +19 -0
- data/lib/rubocop/cop/rspec/mixin/top_level_group.rb +54 -0
- data/lib/rubocop/cop/rspec/mixin/variable.rb +21 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +2 -3
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +4 -1
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +3 -1
- data/lib/rubocop/cop/rspec/named_subject.rb +11 -12
- data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
- data/lib/rubocop/cop/rspec/not_to_not.rb +2 -0
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +4 -1
- data/lib/rubocop/cop/rspec/pending.rb +17 -5
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +8 -3
- 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 +6 -2
- 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 +22 -11
- data/lib/rubocop/cop/rspec/shared_examples.rb +4 -1
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +4 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +2 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +17 -6
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +2 -0
- data/lib/rubocop/cop/rspec/variable_definition.rb +1 -1
- data/lib/rubocop/cop/rspec/variable_name.rb +1 -1
- 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 +0 -1
- data/lib/rubocop/rspec/align_let_brace.rb +1 -1
- data/lib/rubocop/rspec/concept.rb +2 -2
- data/lib/rubocop/rspec/config_formatter.rb +5 -3
- data/lib/rubocop/rspec/corrector/move_node.rb +7 -10
- data/lib/rubocop/rspec/example.rb +5 -0
- data/lib/rubocop/rspec/example_group.rb +15 -5
- data/lib/rubocop/rspec/hook.rb +2 -1
- data/lib/rubocop/rspec/inject.rb +4 -2
- data/lib/rubocop/rspec/language.rb +159 -115
- data/lib/rubocop/rspec/language/node_pattern.rb +7 -24
- data/lib/rubocop/rspec/node.rb +1 -1
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +27 -16
- data/lib/rubocop/cop/rspec/cop.rb +0 -10
- data/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +0 -41
- data/lib/rubocop/rspec.rb +0 -12
- data/lib/rubocop/rspec/empty_line_separation.rb +0 -48
- data/lib/rubocop/rspec/final_end_location.rb +0 -17
- data/lib/rubocop/rspec/top_level_describe.rb +0 -52
- data/lib/rubocop/rspec/top_level_group.rb +0 -57
- data/lib/rubocop/rspec/variable.rb +0 -16
@@ -18,12 +18,12 @@ module RuboCop
|
|
18
18
|
# # ...
|
19
19
|
# end
|
20
20
|
#
|
21
|
-
# @see https://github.com/rubocop
|
21
|
+
# @see https://github.com/rubocop/rubocop-rspec/issues/735
|
22
22
|
class DescribedClassModuleWrapping < Base
|
23
23
|
MSG = 'Avoid opening modules and defining specs within them.'
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# @!method find_rspec_blocks(node)
|
26
|
+
def_node_search :find_rspec_blocks, block_pattern('#ExampleGroups.all')
|
27
27
|
|
28
28
|
def on_module(node)
|
29
29
|
find_rspec_blocks(node) do
|
@@ -47,7 +47,8 @@ module RuboCop
|
|
47
47
|
|
48
48
|
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
|
49
49
|
|
50
|
-
|
50
|
+
# @!method rspec_method?(node)
|
51
|
+
def_node_matcher :rspec_method?, send_pattern('#ALL.all')
|
51
52
|
|
52
53
|
def on_send(node)
|
53
54
|
return unless rspec_method?(node)
|
@@ -5,8 +5,6 @@ module RuboCop
|
|
5
5
|
module RSpec
|
6
6
|
# Checks if an example group does not include any tests.
|
7
7
|
#
|
8
|
-
# This cop is configurable using the `CustomIncludeMethods` option
|
9
|
-
#
|
10
8
|
# @example usage
|
11
9
|
#
|
12
10
|
# # bad
|
@@ -37,31 +35,6 @@ module RuboCop
|
|
37
35
|
# describe Bacon do
|
38
36
|
# pending 'will add tests later'
|
39
37
|
# end
|
40
|
-
#
|
41
|
-
# @example configuration
|
42
|
-
#
|
43
|
-
# # .rubocop.yml
|
44
|
-
# # RSpec/EmptyExampleGroup:
|
45
|
-
# # CustomIncludeMethods:
|
46
|
-
# # - include_tests
|
47
|
-
#
|
48
|
-
# # spec_helper.rb
|
49
|
-
# RSpec.configure do |config|
|
50
|
-
# config.alias_it_behaves_like_to(:include_tests)
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# # bacon_spec.rb
|
54
|
-
# describe Bacon do
|
55
|
-
# let(:bacon) { Bacon.new(chunkiness) }
|
56
|
-
# let(:chunkiness) { false }
|
57
|
-
#
|
58
|
-
# context 'extra chunky' do # not flagged by rubocop
|
59
|
-
# let(:chunkiness) { true }
|
60
|
-
#
|
61
|
-
# include_tests 'shared tests'
|
62
|
-
# end
|
63
|
-
# end
|
64
|
-
#
|
65
38
|
class EmptyExampleGroup < Base
|
66
39
|
MSG = 'Empty example group detected.'
|
67
40
|
|
@@ -76,7 +49,7 @@ module RuboCop
|
|
76
49
|
# @param node [RuboCop::AST::Node]
|
77
50
|
# @yield [RuboCop::AST::Node] example group body
|
78
51
|
def_node_matcher :example_group_body, <<~PATTERN
|
79
|
-
(block #{ExampleGroups
|
52
|
+
(block #{send_pattern('#ExampleGroups.all')} args $_)
|
80
53
|
PATTERN
|
81
54
|
|
82
55
|
# @!method example_or_group_or_include?(node)
|
@@ -95,12 +68,10 @@ module RuboCop
|
|
95
68
|
# @return [Array<RuboCop::AST::Node>] matching nodes
|
96
69
|
def_node_matcher :example_or_group_or_include?, <<~PATTERN
|
97
70
|
{
|
98
|
-
#{
|
99
|
-
|
100
|
-
|
101
|
-
#{Includes
|
102
|
-
#{Includes::ALL.block_pattern}
|
103
|
-
(send nil? #custom_include? ...)
|
71
|
+
#{block_pattern(
|
72
|
+
'{#Examples.all #ExampleGroups.all #Includes.all}'
|
73
|
+
)}
|
74
|
+
#{send_pattern('{#Examples.all #Includes.all}')}
|
104
75
|
}
|
105
76
|
PATTERN
|
106
77
|
|
@@ -120,7 +91,7 @@ module RuboCop
|
|
120
91
|
# @param node [RuboCop::AST::Node]
|
121
92
|
# @return [Array<RuboCop::AST::Node>] matching nodes
|
122
93
|
def_node_matcher :examples_inside_block?, <<~PATTERN
|
123
|
-
(block !#{Hooks
|
94
|
+
(block !#{send_pattern('#Hooks.all')} _ #examples?)
|
124
95
|
PATTERN
|
125
96
|
|
126
97
|
# @!method examples_directly_or_in_block?(node)
|
@@ -192,16 +163,6 @@ module RuboCop
|
|
192
163
|
def examples_in_branches?(if_node)
|
193
164
|
if_node.branches.any? { |branch| examples?(branch) }
|
194
165
|
end
|
195
|
-
|
196
|
-
def custom_include?(method_name)
|
197
|
-
custom_include_methods.include?(method_name)
|
198
|
-
end
|
199
|
-
|
200
|
-
def custom_include_methods
|
201
|
-
cop_config
|
202
|
-
.fetch('CustomIncludeMethods', [])
|
203
|
-
.map(&:to_sym)
|
204
|
-
end
|
205
166
|
end
|
206
167
|
end
|
207
168
|
end
|
@@ -28,8 +28,9 @@ module RuboCop
|
|
28
28
|
|
29
29
|
MSG = 'Empty hook detected.'
|
30
30
|
|
31
|
+
# @!method empty_hook?(node)
|
31
32
|
def_node_matcher :empty_hook?, <<~PATTERN
|
32
|
-
(block $#{Hooks
|
33
|
+
(block $#{send_pattern('#Hooks.all')} _ nil?)
|
33
34
|
PATTERN
|
34
35
|
|
35
36
|
def on_block(node)
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# let(:foo) { bar }
|
17
17
|
class EmptyLineAfterSubject < Base
|
18
18
|
extend AutoCorrector
|
19
|
-
include
|
19
|
+
include EmptyLineSeparation
|
20
20
|
|
21
21
|
MSG = 'Add an empty line after `%<subject>s`.'
|
22
22
|
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
|
33
33
|
def in_spec_block?(node)
|
34
34
|
node.each_ancestor(:block).any? do |ancestor|
|
35
|
-
Examples
|
35
|
+
Examples.all(ancestor.method_name)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -25,29 +25,43 @@ module RuboCop
|
|
25
25
|
# result = service.call
|
26
26
|
# expect(result).to be(true)
|
27
27
|
# end
|
28
|
+
#
|
29
|
+
# You can set literals you want to fold with `CountAsOne`.
|
30
|
+
# Available are: 'array', 'hash', and 'heredoc'. Each literal
|
31
|
+
# will be counted as one line regardless of its actual size.
|
32
|
+
#
|
33
|
+
# @example CountAsOne: ['array', 'heredoc']
|
34
|
+
#
|
35
|
+
# it do
|
36
|
+
# array = [ # +1
|
37
|
+
# 1,
|
38
|
+
# 2
|
39
|
+
# ]
|
40
|
+
#
|
41
|
+
# hash = { # +3
|
42
|
+
# key: 'value'
|
43
|
+
# }
|
44
|
+
#
|
45
|
+
# msg = <<~HEREDOC # +1
|
46
|
+
# Heredoc
|
47
|
+
# content.
|
48
|
+
# HEREDOC
|
49
|
+
# end # 5 points
|
28
50
|
class ExampleLength < Base
|
29
51
|
include CodeLength
|
30
52
|
|
31
|
-
|
53
|
+
LABEL = 'Example'
|
32
54
|
|
33
55
|
def on_block(node)
|
34
56
|
return unless example?(node)
|
35
57
|
|
36
|
-
|
37
|
-
|
38
|
-
return unless length > max_length
|
39
|
-
|
40
|
-
add_offense(node, message: message(length))
|
58
|
+
check_code_length(node)
|
41
59
|
end
|
42
60
|
|
43
61
|
private
|
44
62
|
|
45
|
-
def
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def message(length)
|
50
|
-
format(MSG, total: length, max: max_length)
|
63
|
+
def cop_label
|
64
|
+
LABEL
|
51
65
|
end
|
52
66
|
end
|
53
67
|
end
|
@@ -45,10 +45,11 @@ module RuboCop
|
|
45
45
|
|
46
46
|
SUPPORTED_MATCHERS = %i[eq eql equal be].freeze
|
47
47
|
|
48
|
+
# @!method expect_literal(node)
|
48
49
|
def_node_matcher :expect_literal, <<~PATTERN
|
49
50
|
(send
|
50
51
|
(send nil? :expect $#literal?)
|
51
|
-
#
|
52
|
+
#Runners.all
|
52
53
|
{
|
53
54
|
(send (send nil? $:be) :== $_)
|
54
55
|
(send nil? $_ $_ ...)
|
@@ -60,6 +61,7 @@ module RuboCop
|
|
60
61
|
expect_literal(node) do |actual, matcher, expected|
|
61
62
|
add_offense(actual.source_range) do |corrector|
|
62
63
|
next unless SUPPORTED_MATCHERS.include?(matcher)
|
64
|
+
next if literal?(expected)
|
63
65
|
|
64
66
|
swap(corrector, actual, expected)
|
65
67
|
end
|
@@ -35,11 +35,14 @@ module RuboCop
|
|
35
35
|
|
36
36
|
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
|
37
37
|
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
|
38
|
+
RESTRICT_ON_SEND = %i[change].freeze
|
38
39
|
|
40
|
+
# @!method expect_change_with_arguments(node)
|
39
41
|
def_node_matcher :expect_change_with_arguments, <<-PATTERN
|
40
42
|
(send nil? :change ({const send} nil? $_) (sym $_))
|
41
43
|
PATTERN
|
42
44
|
|
45
|
+
# @!method expect_change_with_block(node)
|
43
46
|
def_node_matcher :expect_change_with_block, <<-PATTERN
|
44
47
|
(block
|
45
48
|
(send nil? :change)
|
@@ -23,7 +23,8 @@ module RuboCop
|
|
23
23
|
class ExpectInHook < Base
|
24
24
|
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'
|
25
25
|
|
26
|
-
|
26
|
+
# @!method expectation(node)
|
27
|
+
def_node_search :expectation, send_pattern('#Expectations.all')
|
27
28
|
|
28
29
|
def on_block(node)
|
29
30
|
return unless hook?(node)
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
# # good
|
16
16
|
# expect { my_app.print_report }.to output('Hello World').to_stdout
|
17
17
|
class ExpectOutput < Base
|
18
|
-
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
|
18
|
+
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` ' \
|
19
19
|
'instead of mutating $%<name>s.'
|
20
20
|
|
21
21
|
def on_gvasgn(node)
|
@@ -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
|
@@ -57,16 +57,18 @@ module RuboCop
|
|
57
57
|
# my_class_spec.rb # describe MyClass, '#method'
|
58
58
|
#
|
59
59
|
class FilePath < Base
|
60
|
-
include
|
60
|
+
include TopLevelGroup
|
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)
|
@@ -82,30 +84,39 @@ module RuboCop
|
|
82
84
|
private
|
83
85
|
|
84
86
|
def ensure_correct_file_path(send_node, described_class, arguments)
|
85
|
-
|
86
|
-
return if filename_ends_with?(
|
87
|
-
|
88
|
-
|
87
|
+
pattern = pattern_for(described_class, arguments.first)
|
88
|
+
return if filename_ends_with?(pattern)
|
89
|
+
|
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
|
-
return
|
102
|
+
def pattern_for(described_class, method_name)
|
103
|
+
return pattern_for_spec_suffix_only? if spec_suffix_only?
|
97
104
|
|
98
|
-
|
105
|
+
[
|
106
|
+
expected_path(described_class),
|
107
|
+
name_pattern(method_name),
|
108
|
+
'[^/]*_spec\.rb'
|
109
|
+
].join
|
99
110
|
end
|
100
111
|
|
101
|
-
def
|
102
|
-
'
|
112
|
+
def pattern_for_spec_suffix_only?
|
113
|
+
'.*_spec\.rb'
|
103
114
|
end
|
104
115
|
|
105
|
-
def
|
116
|
+
def name_pattern(method_name)
|
106
117
|
return unless method_name&.str_type?
|
107
118
|
|
108
|
-
"
|
119
|
+
".*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
109
120
|
end
|
110
121
|
|
111
122
|
def expected_path(constant)
|
@@ -131,11 +142,9 @@ module RuboCop
|
|
131
142
|
cop_config['IgnoreMethods']
|
132
143
|
end
|
133
144
|
|
134
|
-
def filename_ends_with?(
|
135
|
-
filename =
|
136
|
-
|
137
|
-
.gsub('../', '')
|
138
|
-
File.fnmatch?("*#{glob}", filename)
|
145
|
+
def filename_ends_with?(pattern)
|
146
|
+
filename = File.expand_path(processed_source.buffer.name)
|
147
|
+
filename.match?("#{pattern}$")
|
139
148
|
end
|
140
149
|
|
141
150
|
def relevant_rubocop_rspec_file?(_file)
|