sevencop 0.24.4 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/default.yml +1 -0
- data/lib/rubocop/cop/sevencop/rspec_examples_in_same_group.rb +57 -18
- data/lib/sevencop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 922dc5655a1c67a3c6cbe88b4f5b4ca72fc6a504acb678451ca2aece5a7ac0b8
|
4
|
+
data.tar.gz: f00c654f92a7c6a26e4b6514dbaf68adc3a0a6c62efd7f113740675b0104a53f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f21bb92a5a4409c777ba0770728f2e03d9ddc3fcebd75f5204f628155b99dbbf25006f37af1f5fdd58742cdce53400e201708194d5db46da5a53d5a269bc004
|
7
|
+
data.tar.gz: 7c1ecca97ecacebad51e38ff1005e7c500586b85f6d4ee3de816dc3ddb846cd0faeca19520ca5dd1edf1f0296b94a6fc631a53deaf8bb4745021f4fdfccdb08c
|
data/Gemfile.lock
CHANGED
data/config/default.yml
CHANGED
@@ -139,6 +139,7 @@ Sevencop/RSpecExamplesInSameGroup:
|
|
139
139
|
Combine examples in the same groups in the time-consuming kinds of specs.
|
140
140
|
Enabled: false
|
141
141
|
VersionAdded: '0.17'
|
142
|
+
IncludeSharedExamples: false
|
142
143
|
Include:
|
143
144
|
- spec/controllers/**/*
|
144
145
|
- spec/requests/**/*
|
@@ -6,7 +6,6 @@ module RuboCop
|
|
6
6
|
# Combine examples in same group in the time-consuming kinds of specs.
|
7
7
|
#
|
8
8
|
# @example
|
9
|
-
#
|
10
9
|
# # bad
|
11
10
|
# context 'when user is logged in' do
|
12
11
|
# it 'returns 200' do
|
@@ -27,20 +26,42 @@ module RuboCop
|
|
27
26
|
# end
|
28
27
|
# end
|
29
28
|
#
|
29
|
+
# # bad - IncludeSharedExamples: true
|
30
|
+
# context 'when user is logged in' do
|
31
|
+
# it 'returns 200' do
|
32
|
+
# subject
|
33
|
+
# expect(response).to have_http_status(200)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# includes_examples 'creates Foo'
|
37
|
+
# end
|
30
38
|
class RSpecExamplesInSameGroup < Base
|
31
|
-
|
39
|
+
METHOD_NAMES_FOR_REGULAR_EXAMPLE = ::Set[
|
40
|
+
:example,
|
32
41
|
:it,
|
33
42
|
:its,
|
34
|
-
:specify,
|
35
|
-
:example,
|
36
43
|
:scenario,
|
44
|
+
:specify
|
37
45
|
].freeze
|
38
46
|
|
47
|
+
METHOD_NAMES_FOR_SHARED_EXAMPLES = ::Set[
|
48
|
+
:include_examples,
|
49
|
+
:it_behaves_like,
|
50
|
+
:it_should_behave_like
|
51
|
+
]
|
52
|
+
|
39
53
|
MSG = 'Combine examples in the same group in the time-consuming kinds of specs.'
|
40
54
|
|
41
|
-
|
55
|
+
RESTRICT_ON_SEND = [
|
56
|
+
*METHOD_NAMES_FOR_REGULAR_EXAMPLE,
|
57
|
+
*METHOD_NAMES_FOR_SHARED_EXAMPLES
|
58
|
+
].freeze
|
59
|
+
|
60
|
+
# @param node [RuboCop::AST::SendNode]
|
42
61
|
# @return [void]
|
43
|
-
def
|
62
|
+
def on_send(node)
|
63
|
+
node = node.block_node || node
|
64
|
+
|
44
65
|
return unless example?(node)
|
45
66
|
|
46
67
|
previous_sibling_example = previous_sibling_example_of(node)
|
@@ -48,27 +69,45 @@ module RuboCop
|
|
48
69
|
|
49
70
|
add_offense(node)
|
50
71
|
end
|
51
|
-
alias on_numblock on_block
|
52
72
|
|
53
73
|
private
|
54
74
|
|
55
|
-
#
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
75
|
+
# @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
|
76
|
+
# @return [Boolean]
|
77
|
+
def example?(node)
|
78
|
+
if include_shared_examples?
|
79
|
+
regular_example?(node) || shared_example?(node)
|
80
|
+
else
|
81
|
+
regular_example?(node)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# @return [Boolean]
|
86
|
+
def include_shared_examples?
|
87
|
+
cop_config['IncludeSharedExamples']
|
88
|
+
end
|
64
89
|
|
65
|
-
# @param node [RuboCop::AST::BlockNode]
|
66
|
-
# @return [RuboCop::AST::BlockNode, nil]
|
90
|
+
# @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
|
91
|
+
# @return [RuboCop::AST::BlockNode, RuboCop::AST::SendNode, nil]
|
67
92
|
def previous_sibling_example_of(node)
|
93
|
+
return unless node.parent&.begin_type?
|
94
|
+
|
68
95
|
node.left_siblings.find do |sibling|
|
69
96
|
sibling.is_a?(::RuboCop::AST::Node) && example?(sibling)
|
70
97
|
end
|
71
98
|
end
|
99
|
+
|
100
|
+
# @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
|
101
|
+
# @return [Boolean]
|
102
|
+
def regular_example?(node)
|
103
|
+
METHOD_NAMES_FOR_REGULAR_EXAMPLE.include?(node.method_name)
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param node [RuboCop::AST::BlockNode, RuboCop::AST::SendNode]
|
107
|
+
# @return [Boolean]
|
108
|
+
def shared_example?(node)
|
109
|
+
METHOD_NAMES_FOR_SHARED_EXAMPLES.include?(node.method_name)
|
110
|
+
end
|
72
111
|
end
|
73
112
|
end
|
74
113
|
end
|
data/lib/sevencop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevencop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|