rubocop-rspec-guide 0.2.0 → 0.2.2
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: 9093b8623b631c2b9ddaf15d1b72a1638c499d93e9820687dd37ec6e71f27d30
|
|
4
|
+
data.tar.gz: '09d4eb92564fcfd55bb9d72b15eaf690a5d1e8ada0621f6f281de369a2c1c683'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: beaebca72cb64609567dd9bc687961cfe193d228d1a25a50de8371a1e605f8265cc596ed2695e942b0d5f679a1f23d2581ef8a8aec176d7c26a5174c323146eb
|
|
7
|
+
data.tar.gz: 3783cee1af2fa2d784f0ad67ce7bcf08019aab358e7d6f5c2f9d53f7b26d5bf0dbe9dd55566c0bb347e30c331ae26f0f6467d3c51972cf1071cda15cab1e8d4c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.2] - 2025-10-29
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **RSpecGuide/DuplicateLetValues**: Fix crash when encountering empty let blocks (e.g., `let(:foo) {}`)
|
|
7
|
+
- Added nil check in `simple_value?` method to handle cases where let block has no body
|
|
8
|
+
|
|
9
|
+
## [0.2.1] - 2025-10-29
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- **RSpecGuide/HappyPathFirst**: Allow corner case contexts when examples (it/specify) appear before first context
|
|
13
|
+
- Examples before contexts are considered happy path
|
|
14
|
+
- No offense if at least one example exists before the first context
|
|
15
|
+
|
|
3
16
|
## [0.2.0] - 2025-10-28
|
|
4
17
|
|
|
5
18
|
### Changed
|
|
@@ -159,6 +159,8 @@ module RuboCop
|
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
def simple_value?(node)
|
|
162
|
+
return false if node.nil?
|
|
163
|
+
|
|
162
164
|
# Values we can safely compare by source
|
|
163
165
|
return true if node.sym_type? || node.str_type? || node.int_type? || node.float_type?
|
|
164
166
|
return true if node.true_type? || node.false_type? || node.nil_type?
|
|
@@ -6,6 +6,10 @@ module RuboCop
|
|
|
6
6
|
# Checks that corner cases are not the first context in a describe block.
|
|
7
7
|
# Happy path should come first for better readability.
|
|
8
8
|
#
|
|
9
|
+
# The cop allows corner case contexts to appear first if there are
|
|
10
|
+
# example blocks (it/specify) before the first context, as those examples
|
|
11
|
+
# represent the happy path.
|
|
12
|
+
#
|
|
9
13
|
# @example
|
|
10
14
|
# # bad
|
|
11
15
|
# describe '#process' do
|
|
@@ -37,6 +41,17 @@ module RuboCop
|
|
|
37
41
|
# end
|
|
38
42
|
# end
|
|
39
43
|
#
|
|
44
|
+
# # good - examples before first context represent happy path
|
|
45
|
+
# describe '#add_child' do
|
|
46
|
+
# it 'adds child to children collection' do
|
|
47
|
+
# # ...
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# context 'but child is already in collection' do
|
|
51
|
+
# # ...
|
|
52
|
+
# end
|
|
53
|
+
# end
|
|
54
|
+
#
|
|
40
55
|
class HappyPathFirst < Base
|
|
41
56
|
MSG = "Place happy path contexts before corner cases. " \
|
|
42
57
|
"First context appears to be a corner case: %<description>s"
|
|
@@ -67,6 +82,10 @@ module RuboCop
|
|
|
67
82
|
contexts = collect_direct_child_contexts(node)
|
|
68
83
|
return if contexts.size < 2
|
|
69
84
|
|
|
85
|
+
# If there are any examples (it/specify) before the first context,
|
|
86
|
+
# this is a happy path, so no offense
|
|
87
|
+
return if has_examples_before_first_context?(node, contexts.first)
|
|
88
|
+
|
|
70
89
|
# Check first context
|
|
71
90
|
context_with_description?(contexts.first) do |description|
|
|
72
91
|
if corner_case_context?(description)
|
|
@@ -80,6 +99,30 @@ module RuboCop
|
|
|
80
99
|
|
|
81
100
|
private
|
|
82
101
|
|
|
102
|
+
def has_examples_before_first_context?(node, first_context)
|
|
103
|
+
body = node.body
|
|
104
|
+
return false unless body
|
|
105
|
+
|
|
106
|
+
children = body.begin_type? ? body.children : [body]
|
|
107
|
+
|
|
108
|
+
children.each do |child|
|
|
109
|
+
# Stop when we reach the first context
|
|
110
|
+
break if child == first_context
|
|
111
|
+
|
|
112
|
+
# Check if this is an example (it/specify)
|
|
113
|
+
return true if example?(child)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
false
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def example?(node)
|
|
120
|
+
return false unless node.block_type?
|
|
121
|
+
|
|
122
|
+
send_node = node.send_node
|
|
123
|
+
send_node.method?(:it) || send_node.method?(:specify)
|
|
124
|
+
end
|
|
125
|
+
|
|
83
126
|
def collect_direct_child_contexts(node)
|
|
84
127
|
body = node.body
|
|
85
128
|
return [] unless body
|