sevencop 0.24.3 → 0.25.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
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
@@ -128,7 +128,7 @@ Sevencop/RequireOrdered:
|
|
128
128
|
|
129
129
|
Sevencop/RSpecDescribeHttpEndpoint:
|
130
130
|
Description: |
|
131
|
-
Pass HTTP endpoint identifier to top-level `describe` on request-specs.
|
131
|
+
Pass HTTP endpoint identifier (e.g. `GET /users`) to top-level `describe` on request-specs.
|
132
132
|
Enabled: false
|
133
133
|
VersionAdded: '0.18'
|
134
134
|
Include:
|
@@ -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/**/*
|
@@ -3,7 +3,11 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Sevencop
|
6
|
-
# Pass HTTP endpoint identifier to top-level `describe` on request-specs.
|
6
|
+
# Pass HTTP endpoint identifier (e.g. `GET /users`) to top-level `describe` on request-specs.
|
7
|
+
#
|
8
|
+
# In request-specs, one should be aware that it is a test type for endpoints at HTTP layer.
|
9
|
+
# Therefore it is good practice to put the HTTP method and path in the top-level description
|
10
|
+
# and to separate examples groups by each endpoint.
|
7
11
|
#
|
8
12
|
# @see https://github.com/r7kamura/rspec-request_describer
|
9
13
|
#
|
@@ -14,7 +18,7 @@ module RuboCop
|
|
14
18
|
# # good
|
15
19
|
# RSpec.describe 'GET /users'
|
16
20
|
class RSpecDescribeHttpEndpoint < Base
|
17
|
-
MSG = 'Pass HTTP endpoint identifier to top-level `describe` on request-specs.'
|
21
|
+
MSG = 'Pass HTTP endpoint identifier (e.g. `GET /users`) to top-level `describe` on request-specs.'
|
18
22
|
|
19
23
|
RESTRICT_ON_SEND = %i[
|
20
24
|
describe
|
@@ -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
|