gl_rubocop 0.5.2 → 0.5.3
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/default.yml +6 -0
- data/lib/gl_rubocop/gl_cops/no_stubbing_env.rb +42 -0
- data/lib/gl_rubocop/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1047a8465eb718c62b4582a7c18f339e17acb15bf0861c60460d21f2f1d74a65
|
|
4
|
+
data.tar.gz: c85258ff5eb9526fc05b9eb6d8dd15aa8b63f94fe868ed434356259080153fc8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39d62d81dfbb69a9e213efb8df7f02486906849e9218572d3a48a76758715e3f598c14bbbcce9abfd483edc96f32f8d9dcb2167c44085774bd3e71573ac552a9
|
|
7
|
+
data.tar.gz: c32264166f4d1ba98cd73606541671718308de01b47e38c9b08cc59d9aa4496f1ea9a33385807e1aabe9a129e2c920e0433266107588028ad038c98b83e595af
|
data/default.yml
CHANGED
|
@@ -12,6 +12,7 @@ require:
|
|
|
12
12
|
- ./lib/gl_rubocop/gl_cops/consolidate_request_system_specs.rb
|
|
13
13
|
- ./lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
|
14
14
|
- ./lib/gl_rubocop/gl_cops/limit_flash_options.rb
|
|
15
|
+
- ./lib/gl_rubocop/gl_cops/no_stubbing_env.rb
|
|
15
16
|
- ./lib/gl_rubocop/gl_cops/no_stubbing_perform_async.rb
|
|
16
17
|
- ./lib/gl_rubocop/gl_cops/prevent_haml_files.rb
|
|
17
18
|
- ./lib/gl_rubocop/gl_cops/rails_cache.rb
|
|
@@ -62,6 +63,11 @@ GLCops/InteractorInheritsFromInteractorBase:
|
|
|
62
63
|
GLCops/LimitFlashOptions:
|
|
63
64
|
Enabled: true
|
|
64
65
|
|
|
66
|
+
GLCops/NoStubbingEnv:
|
|
67
|
+
Enabled: true
|
|
68
|
+
Include:
|
|
69
|
+
- "**/*spec.rb"
|
|
70
|
+
|
|
65
71
|
GLCops/NoStubbingPerformAsync:
|
|
66
72
|
Enabled: true
|
|
67
73
|
Include:
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module GLRubocop
|
|
2
|
+
module GLCops
|
|
3
|
+
# This cop ensures that you don't stub ENV with `allow`/`expect` + `receive`.
|
|
4
|
+
#
|
|
5
|
+
# Stubbing ENV this way (even with `and_call_original`) only stubs the env vars the
|
|
6
|
+
# spec explicitly knows about. Any var that is read but not stubbed - for example a
|
|
7
|
+
# var that is present on CI but not locally, or vice versa - behaves inconsistently
|
|
8
|
+
# and causes flaky failures.
|
|
9
|
+
#
|
|
10
|
+
# Instead, replace ENV wholesale with `stub_const`, building the hash from the real
|
|
11
|
+
# ENV so unrelated vars keep working everywhere:
|
|
12
|
+
#
|
|
13
|
+
# Good:
|
|
14
|
+
# stub_const('ENV', ENV.to_hash.except('VAR_TO_UNSET').merge('VAR_TO_SET' => 'value'))
|
|
15
|
+
#
|
|
16
|
+
# Bad:
|
|
17
|
+
# allow(ENV).to receive(:[]).and_call_original
|
|
18
|
+
# allow(ENV).to receive(:[]).with('VAR_TO_SET').and_return('value')
|
|
19
|
+
# expect(ENV).to receive(:fetch)
|
|
20
|
+
class NoStubbingEnv < RuboCop::Cop::Base
|
|
21
|
+
MSG = "Don't stub ENV with allow/expect + receive. Use " \
|
|
22
|
+
"stub_const('ENV', ENV.to_hash.except('VAR_TO_UNSET')." \
|
|
23
|
+
"merge('VAR_TO_SET' => 'value')) instead, so unrelated ENV vars " \
|
|
24
|
+
'(e.g. on CI) keep working.'.freeze
|
|
25
|
+
|
|
26
|
+
# Match `allow(ENV).to receive(...)` / `expect(ENV).not_to receive(...)`, including
|
|
27
|
+
# chained forms like `.and_call_original`, `.and_return(...)`, `.with(...)`.
|
|
28
|
+
def_node_matcher :stubbing_env?, <<~PATTERN
|
|
29
|
+
(send
|
|
30
|
+
(send nil? {:allow :expect} (const {nil? cbase} :ENV))
|
|
31
|
+
{:to :not_to :to_not}
|
|
32
|
+
`(send nil? :receive ...))
|
|
33
|
+
PATTERN
|
|
34
|
+
|
|
35
|
+
def on_send(node)
|
|
36
|
+
return unless stubbing_env?(node)
|
|
37
|
+
|
|
38
|
+
add_offense(node)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/gl_rubocop/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gl_rubocop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Give Lively
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|
|
@@ -166,6 +166,7 @@ files:
|
|
|
166
166
|
- lib/gl_rubocop/gl_cops/consolidate_request_system_specs.rb
|
|
167
167
|
- lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
|
|
168
168
|
- lib/gl_rubocop/gl_cops/limit_flash_options.rb
|
|
169
|
+
- lib/gl_rubocop/gl_cops/no_stubbing_env.rb
|
|
169
170
|
- lib/gl_rubocop/gl_cops/no_stubbing_perform_async.rb
|
|
170
171
|
- lib/gl_rubocop/gl_cops/prevent_haml_files.rb
|
|
171
172
|
- lib/gl_rubocop/gl_cops/rails_cache.rb
|
|
@@ -201,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
201
202
|
- !ruby/object:Gem::Version
|
|
202
203
|
version: '0'
|
|
203
204
|
requirements: []
|
|
204
|
-
rubygems_version: 3.
|
|
205
|
+
rubygems_version: 3.5.22
|
|
205
206
|
signing_key:
|
|
206
207
|
specification_version: 4
|
|
207
208
|
summary: A shareable configuration of Give Lively's rubocop rules.
|