rubocop-rspec 1.44.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -1
- data/README.md +5 -1
- data/config/default.yml +171 -81
- 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 +1 -1
- data/lib/rubocop/cop/rspec/base.rb +6 -55
- data/lib/rubocop/cop/rspec/be.rb +2 -2
- data/lib/rubocop/cop/rspec/be_eql.rb +1 -0
- data/lib/rubocop/cop/rspec/before_after_all.rb +5 -3
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +4 -2
- data/lib/rubocop/cop/rspec/capybara/feature_methods.rb +3 -2
- data/lib/rubocop/cop/rspec/capybara/visibility_matcher.rb +2 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_method.rb +2 -2
- data/lib/rubocop/cop/rspec/describe_symbol.rb +1 -0
- data/lib/rubocop/cop/rspec/described_class.rb +1 -2
- data/lib/rubocop/cop/rspec/described_class_module_wrapping.rb +1 -2
- data/lib/rubocop/cop/rspec/dialect.rb +1 -1
- data/lib/rubocop/cop/rspec/empty_example_group.rb +6 -45
- data/lib/rubocop/cop/rspec/empty_hook.rb +1 -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/expect_actual.rb +2 -1
- data/lib/rubocop/cop/rspec/expect_change.rb +1 -0
- data/lib/rubocop/cop/rspec/expect_in_hook.rb +1 -1
- data/lib/rubocop/cop/rspec/expect_output.rb +1 -1
- data/lib/rubocop/cop/rspec/factory_bot/create_list.rb +1 -0
- data/lib/rubocop/cop/rspec/factory_bot/factory_class_name.rb +1 -0
- data/lib/rubocop/cop/rspec/file_path.rb +24 -17
- data/lib/rubocop/cop/rspec/focus.rb +43 -8
- data/lib/rubocop/cop/rspec/hook_argument.rb +2 -4
- data/lib/rubocop/cop/rspec/hooks_before_examples.rb +2 -2
- data/lib/rubocop/cop/rspec/implicit_block_expectation.rb +1 -0
- data/lib/rubocop/cop/rspec/implicit_expect.rb +1 -1
- data/lib/rubocop/cop/rspec/implicit_subject.rb +1 -0
- data/lib/rubocop/cop/rspec/instance_spy.rb +1 -1
- data/lib/rubocop/cop/rspec/instance_variable.rb +1 -1
- data/lib/rubocop/cop/rspec/it_behaves_like.rb +2 -1
- data/lib/rubocop/cop/rspec/iterated_expectation.rb +1 -1
- data/lib/rubocop/cop/rspec/let_before_examples.rb +2 -2
- data/lib/rubocop/cop/rspec/let_setup.rb +7 -4
- data/lib/rubocop/cop/rspec/message_chain.rb +4 -10
- data/lib/rubocop/cop/rspec/message_expectation.rb +1 -0
- data/lib/rubocop/cop/rspec/message_spies.rb +3 -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 +20 -0
- data/lib/rubocop/cop/rspec/multiple_describes.rb +2 -3
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +1 -1
- data/lib/rubocop/cop/rspec/multiple_memoized_helpers.rb +3 -1
- data/lib/rubocop/cop/rspec/named_subject.rb +8 -12
- data/lib/rubocop/cop/rspec/nested_groups.rb +1 -1
- data/lib/rubocop/cop/rspec/not_to_not.rb +1 -0
- data/lib/rubocop/cop/rspec/overwriting_setup.rb +2 -1
- data/lib/rubocop/cop/rspec/pending.rb +13 -5
- data/lib/rubocop/cop/rspec/predicate_matcher.rb +3 -3
- data/lib/rubocop/cop/rspec/rails/http_status.rb +1 -0
- data/lib/rubocop/cop/rspec/receive_counts.rb +2 -0
- data/lib/rubocop/cop/rspec/receive_never.rb +1 -0
- data/lib/rubocop/cop/rspec/repeated_include_example.rb +3 -2
- data/lib/rubocop/cop/rspec/return_from_stub.rb +1 -0
- data/lib/rubocop/cop/rspec/scattered_setup.rb +1 -1
- data/lib/rubocop/cop/rspec/shared_context.rb +18 -11
- data/lib/rubocop/cop/rspec/shared_examples.rb +3 -1
- data/lib/rubocop/cop/rspec/single_argument_message_chain.rb +2 -1
- data/lib/rubocop/cop/rspec/stubbed_mock.rb +1 -1
- data/lib/rubocop/cop/rspec/subject_stub.rb +16 -6
- data/lib/rubocop/cop/rspec/unspecified_exception.rb +1 -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 +1 -0
- data/lib/rubocop/cop/rspec/void_expect.rb +1 -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_group.rb +15 -5
- data/lib/rubocop/rspec/hook.rb +1 -1
- data/lib/rubocop/rspec/inject.rb +4 -2
- data/lib/rubocop/rspec/language.rb +143 -109
- 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 +12 -15
- 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
@@ -3,32 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module RSpec
|
5
5
|
module Language
|
6
|
-
#
|
6
|
+
# Helper methods to detect RSpec DSL used with send and block
|
7
7
|
module NodePattern
|
8
|
-
|
8
|
+
def send_pattern(string)
|
9
|
+
"(send #rspec? #{string} ...)"
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def_node_matcher :shared_group?, SharedGroups::ALL.block_pattern
|
14
|
-
|
15
|
-
spec_groups = ExampleGroups::ALL + SharedGroups::ALL
|
16
|
-
def_node_matcher :spec_group?, spec_groups.block_pattern
|
17
|
-
|
18
|
-
def_node_matcher :example_group_with_body?, <<-PATTERN
|
19
|
-
(block #{ExampleGroups::ALL.send_pattern} args !nil?)
|
20
|
-
PATTERN
|
21
|
-
|
22
|
-
def_node_matcher :example?, Examples::ALL.block_pattern
|
23
|
-
|
24
|
-
def_node_matcher :hook?, Hooks::ALL.block_pattern
|
25
|
-
|
26
|
-
def_node_matcher :let?, Helpers::ALL.block_or_block_pass_pattern
|
27
|
-
|
28
|
-
def_node_matcher :include?,
|
29
|
-
Includes::ALL.send_or_block_or_block_pass_pattern
|
30
|
-
|
31
|
-
def_node_matcher :subject?, Subject::ALL.block_pattern
|
12
|
+
def block_pattern(string)
|
13
|
+
"(block #{send_pattern(string)} ...)"
|
14
|
+
end
|
32
15
|
end
|
33
16
|
end
|
34
17
|
end
|
data/lib/rubocop/rspec/node.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Backus
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0
|
21
|
+
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '0
|
28
|
+
version: '1.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rubocop-ast
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version:
|
35
|
+
version: 1.1.0
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 1.1.0
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rack
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,7 +156,6 @@ files:
|
|
156
156
|
- lib/rubocop/cop/rspec/capybara/visibility_matcher.rb
|
157
157
|
- lib/rubocop/cop/rspec/context_method.rb
|
158
158
|
- lib/rubocop/cop/rspec/context_wording.rb
|
159
|
-
- lib/rubocop/cop/rspec/cop.rb
|
160
159
|
- lib/rubocop/cop/rspec/describe_class.rb
|
161
160
|
- lib/rubocop/cop/rspec/describe_method.rb
|
162
161
|
- lib/rubocop/cop/rspec/describe_symbol.rb
|
@@ -189,7 +188,6 @@ files:
|
|
189
188
|
- lib/rubocop/cop/rspec/implicit_subject.rb
|
190
189
|
- lib/rubocop/cop/rspec/instance_spy.rb
|
191
190
|
- lib/rubocop/cop/rspec/instance_variable.rb
|
192
|
-
- lib/rubocop/cop/rspec/invalid_predicate_matcher.rb
|
193
191
|
- lib/rubocop/cop/rspec/it_behaves_like.rb
|
194
192
|
- lib/rubocop/cop/rspec/iterated_expectation.rb
|
195
193
|
- lib/rubocop/cop/rspec/leading_subject.rb
|
@@ -200,6 +198,11 @@ files:
|
|
200
198
|
- lib/rubocop/cop/rspec/message_expectation.rb
|
201
199
|
- lib/rubocop/cop/rspec/message_spies.rb
|
202
200
|
- lib/rubocop/cop/rspec/missing_example_group_argument.rb
|
201
|
+
- lib/rubocop/cop/rspec/mixin/comments_help.rb
|
202
|
+
- lib/rubocop/cop/rspec/mixin/empty_line_separation.rb
|
203
|
+
- lib/rubocop/cop/rspec/mixin/final_end_location.rb
|
204
|
+
- lib/rubocop/cop/rspec/mixin/top_level_group.rb
|
205
|
+
- lib/rubocop/cop/rspec/mixin/variable.rb
|
203
206
|
- lib/rubocop/cop/rspec/multiple_describes.rb
|
204
207
|
- lib/rubocop/cop/rspec/multiple_expectations.rb
|
205
208
|
- lib/rubocop/cop/rspec/multiple_memoized_helpers.rb
|
@@ -233,25 +236,19 @@ files:
|
|
233
236
|
- lib/rubocop/cop/rspec/void_expect.rb
|
234
237
|
- lib/rubocop/cop/rspec/yield.rb
|
235
238
|
- lib/rubocop/cop/rspec_cops.rb
|
236
|
-
- lib/rubocop/rspec.rb
|
237
239
|
- lib/rubocop/rspec/align_let_brace.rb
|
238
240
|
- lib/rubocop/rspec/concept.rb
|
239
241
|
- lib/rubocop/rspec/config_formatter.rb
|
240
242
|
- lib/rubocop/rspec/corrector/move_node.rb
|
241
243
|
- lib/rubocop/rspec/description_extractor.rb
|
242
|
-
- lib/rubocop/rspec/empty_line_separation.rb
|
243
244
|
- lib/rubocop/rspec/example.rb
|
244
245
|
- lib/rubocop/rspec/example_group.rb
|
245
246
|
- lib/rubocop/rspec/factory_bot.rb
|
246
|
-
- lib/rubocop/rspec/final_end_location.rb
|
247
247
|
- lib/rubocop/rspec/hook.rb
|
248
248
|
- lib/rubocop/rspec/inject.rb
|
249
249
|
- lib/rubocop/rspec/language.rb
|
250
250
|
- lib/rubocop/rspec/language/node_pattern.rb
|
251
251
|
- lib/rubocop/rspec/node.rb
|
252
|
-
- lib/rubocop/rspec/top_level_describe.rb
|
253
|
-
- lib/rubocop/rspec/top_level_group.rb
|
254
|
-
- lib/rubocop/rspec/variable.rb
|
255
252
|
- lib/rubocop/rspec/version.rb
|
256
253
|
- lib/rubocop/rspec/wording.rb
|
257
254
|
homepage: https://github.com/rubocop-hq/rubocop-rspec
|
@@ -275,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
272
|
- !ruby/object:Gem::Version
|
276
273
|
version: '0'
|
277
274
|
requirements: []
|
278
|
-
rubygems_version: 3.
|
275
|
+
rubygems_version: 3.2.2
|
279
276
|
signing_key:
|
280
277
|
specification_version: 4
|
281
278
|
summary: Code style checking for RSpec files
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module Cop
|
5
|
-
module RSpec
|
6
|
-
# Checks invalid usage for predicate matcher.
|
7
|
-
#
|
8
|
-
# Predicate matcher does not need a question.
|
9
|
-
# This cop checks an unnecessary question in predicate matcher.
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
#
|
13
|
-
# # bad
|
14
|
-
# expect(foo).to be_something?
|
15
|
-
#
|
16
|
-
# # good
|
17
|
-
# expect(foo).to be_something
|
18
|
-
class InvalidPredicateMatcher < Base
|
19
|
-
MSG = 'Omit `?` from `%<matcher>s`.'
|
20
|
-
|
21
|
-
def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
|
22
|
-
(send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
|
23
|
-
PATTERN
|
24
|
-
|
25
|
-
def on_send(node)
|
26
|
-
invalid_predicate_matcher?(node) do |predicate|
|
27
|
-
add_offense(predicate,
|
28
|
-
message: format(MSG, matcher: predicate.method_name))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def predicate?(name)
|
35
|
-
name = name.to_s
|
36
|
-
name.start_with?('be_', 'have_') && name.end_with?('?')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/rubocop/rspec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
# RuboCop RSpec project namespace
|
5
|
-
module RSpec
|
6
|
-
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
7
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
8
|
-
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
9
|
-
|
10
|
-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
11
|
-
end
|
12
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helps determine the offending location if there is not an empty line
|
6
|
-
# following the node. Allows comments to follow directly after.
|
7
|
-
module EmptyLineSeparation
|
8
|
-
include FinalEndLocation
|
9
|
-
include RuboCop::Cop::RangeHelp
|
10
|
-
|
11
|
-
def missing_separating_line_offense(node)
|
12
|
-
return if last_child?(node)
|
13
|
-
|
14
|
-
missing_separating_line(node) do |location|
|
15
|
-
msg = yield(node.method_name)
|
16
|
-
add_offense(location, message: msg) do |corrector|
|
17
|
-
corrector.insert_after(location.end, "\n")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def missing_separating_line(node)
|
23
|
-
line = final_end_location(node).line
|
24
|
-
|
25
|
-
line += 1 while comment_line?(processed_source[line])
|
26
|
-
|
27
|
-
return if processed_source[line].blank?
|
28
|
-
|
29
|
-
yield offending_loc(line)
|
30
|
-
end
|
31
|
-
|
32
|
-
def offending_loc(last_line)
|
33
|
-
offending_line = processed_source[last_line - 1]
|
34
|
-
|
35
|
-
content_length = offending_line.lstrip.length
|
36
|
-
start = offending_line.length - content_length
|
37
|
-
|
38
|
-
source_range(processed_source.buffer, last_line, start, content_length)
|
39
|
-
end
|
40
|
-
|
41
|
-
def last_child?(node)
|
42
|
-
return true unless node.parent&.begin_type?
|
43
|
-
|
44
|
-
node.equal?(node.parent.children.last)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helps find the true end location of nodes which might contain heredocs.
|
6
|
-
module FinalEndLocation
|
7
|
-
def final_end_location(start_node)
|
8
|
-
heredoc_endings =
|
9
|
-
start_node.each_node(:str, :dstr, :xstr)
|
10
|
-
.select(&:heredoc?)
|
11
|
-
.map { |node| node.loc.heredoc_end }
|
12
|
-
|
13
|
-
[start_node.loc.end, *heredoc_endings].max_by(&:line)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helper methods for top level describe cops
|
6
|
-
module TopLevelDescribe
|
7
|
-
extend NodePattern::Macros
|
8
|
-
|
9
|
-
def on_send(node)
|
10
|
-
return unless respond_to?(:on_top_level_describe)
|
11
|
-
return unless top_level_describe?(node)
|
12
|
-
|
13
|
-
on_top_level_describe(node, node.arguments)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def top_level_describe?(node)
|
19
|
-
return false unless node.method?(:describe)
|
20
|
-
|
21
|
-
top_level_nodes.include?(node)
|
22
|
-
end
|
23
|
-
|
24
|
-
def top_level_nodes
|
25
|
-
nodes = describe_statement_children(root_node)
|
26
|
-
# If we have no top level describe statements, we need to check any
|
27
|
-
# blocks on the top level (e.g. after a require).
|
28
|
-
if nodes.empty?
|
29
|
-
nodes = root_node.each_child_node(:block).flat_map do |child|
|
30
|
-
describe_statement_children(child)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
nodes
|
35
|
-
end
|
36
|
-
|
37
|
-
def root_node
|
38
|
-
processed_source.ast
|
39
|
-
end
|
40
|
-
|
41
|
-
def single_top_level_describe?
|
42
|
-
top_level_nodes.one?
|
43
|
-
end
|
44
|
-
|
45
|
-
def describe_statement_children(node)
|
46
|
-
node.each_child_node(:send).select do |element|
|
47
|
-
element.method?(:describe)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helper methods for top level example group cops
|
6
|
-
module TopLevelGroup
|
7
|
-
extend RuboCop::NodePattern::Macros
|
8
|
-
include RuboCop::RSpec::Language
|
9
|
-
|
10
|
-
def_node_matcher :example_or_shared_group?,
|
11
|
-
(ExampleGroups::ALL + SharedGroups::ALL).block_pattern
|
12
|
-
|
13
|
-
def on_new_investigation
|
14
|
-
super
|
15
|
-
|
16
|
-
return unless root_node
|
17
|
-
|
18
|
-
top_level_groups.each do |node|
|
19
|
-
on_top_level_example_group(node) if example_group?(node)
|
20
|
-
on_top_level_group(node)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def top_level_groups
|
25
|
-
@top_level_groups ||=
|
26
|
-
top_level_nodes(root_node).select { |n| example_or_shared_group?(n) }
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
# Dummy methods to be overridden in the consumer
|
32
|
-
def on_top_level_example_group(_node); end
|
33
|
-
|
34
|
-
def on_top_level_group(_node); end
|
35
|
-
|
36
|
-
def top_level_group?(node)
|
37
|
-
top_level_groups.include?(node)
|
38
|
-
end
|
39
|
-
|
40
|
-
def top_level_nodes(node)
|
41
|
-
if node.nil?
|
42
|
-
[]
|
43
|
-
elsif node.begin_type?
|
44
|
-
node.children
|
45
|
-
elsif node.module_type? || node.class_type?
|
46
|
-
top_level_nodes(node.body)
|
47
|
-
else
|
48
|
-
[node]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def root_node
|
53
|
-
processed_source.ast
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module RSpec
|
5
|
-
# Helps check offenses with variable definitions
|
6
|
-
module Variable
|
7
|
-
include Language
|
8
|
-
extend RuboCop::NodePattern::Macros
|
9
|
-
|
10
|
-
def_node_matcher :variable_definition?, <<~PATTERN
|
11
|
-
(send nil? #{(Helpers::ALL + Subject::ALL).node_pattern_union}
|
12
|
-
$({sym str dsym dstr} ...) ...)
|
13
|
-
PATTERN
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|