@@ -61,10 +61,10 @@ class FilePath < Base
61
61
62
62
MSG = 'Spec path should end with `%<suffix>s`.'
63
63
64
- # @!method const_described (node)
65
- def_node_matcher :const_described , <<~PATTERN
64
+ # @!method example_group (node)
65
+ def_node_matcher :example_group , <<~PATTERN
66
66
(block
67
- $(send #rspec? _example_group $(const ...) $...) ...
67
+ $(send #rspec? _example_group $_ $...) ...
68
68
)
69
69
PATTERN
70
70
@@ -74,17 +74,17 @@ class FilePath < Base
74
74
def on_top_level_example_group ( node )
75
75
return unless top_level_groups . one?
76
76
77
- const_described ( node ) do |send_node , described_class , arguments |
77
+ example_group ( node ) do |send_node , example_group , arguments |
78
78
next if routing_spec? ( arguments )
79
79
80
- ensure_correct_file_path ( send_node , described_class , arguments )
80
+ ensure_correct_file_path ( send_node , example_group , arguments )
81
81
end
82
82
end
83
83
84
84
private
85
85
86
- def ensure_correct_file_path ( send_node , described_class , arguments )
87
- pattern = pattern_for ( described_class , arguments . first )
86
+ def ensure_correct_file_path ( send_node , example_group , arguments )
87
+ pattern = pattern_for ( example_group , arguments . first )
88
88
return if filename_ends_with? ( pattern )
89
89
90
90
# For the suffix shown in the offense message, modify the regular
@@ -99,11 +99,13 @@ def routing_spec?(args)
99
99
args . any? ( &method ( :routing_metadata? ) )
100
100
end
101
101
102
- def pattern_for ( described_class , method_name )
103
- return pattern_for_spec_suffix_only? if spec_suffix_only?
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
104
106
105
107
[
106
- expected_path ( described_class ) ,
108
+ expected_path ( example_group ) ,
107
109
name_pattern ( method_name ) ,
108
110
'[^/]*_spec\.rb'
109
111
] . join
0 commit comments