factory_sloth 1.1.0 → 1.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 +6 -0
- data/README.md +3 -0
- data/lib/factory_sloth/create_call_finder.rb +20 -5
- data/lib/factory_sloth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3550aaf57e03aa0da8d68264bab3c4a0a17ed264995859f34cc641e7e376b51b
|
4
|
+
data.tar.gz: d947f5e3533b24b7740d509b5e9b8f3a832a6c535eb81f859ba7c562127c3e5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9abcbc30c854da1ec58f4ab292ab6ed9a851dcbd11bd00291b2902bdec14ec79c21145033c2a984b7243831dd27b426bf5e33f6e9d22272d673a9ff2f61dd97
|
7
|
+
data.tar.gz: '03280bc6477e646583c5af49d46e8bacbf611387181c3e0625e007c019170b697151a78fbd1698a859358a512f483a9949f3b6b27006fe92fc85fd10ccb2b149'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,9 @@ The `conflict` case is rare. It only happens if individual examples were green a
|
|
60
60
|
|
61
61
|
- only works with RSpec so far
|
62
62
|
- downgrades create calls that never run (e.g. in skipped examples)
|
63
|
+
- downgrades create calls that are only checked for an absence of effects
|
64
|
+
- e.g. `a = create(:a); b = create(:b); expect(Record.filtered).to eq [b]`
|
65
|
+
- `# sloth:disable` / `# sloth:enable` comments can be used to control this
|
63
66
|
|
64
67
|
## Development
|
65
68
|
|
@@ -7,29 +7,44 @@ class FactorySloth::CreateCallFinder < Ripper
|
|
7
7
|
new(code).tap(&:parse).locations
|
8
8
|
end
|
9
9
|
|
10
|
-
def initialize(...)
|
10
|
+
def initialize(code, ...)
|
11
11
|
super
|
12
|
+
@code = code
|
13
|
+
@disabled = false
|
12
14
|
@locations = []
|
13
15
|
end
|
14
16
|
private_class_method :new
|
15
17
|
|
18
|
+
def store_location(loc)
|
19
|
+
@locations << loc if loc.instance_of?(Array) && !@disabled
|
20
|
+
end
|
21
|
+
|
16
22
|
def on_ident(name, *)
|
17
23
|
[lineno, column] if %w[create create_list create_pair].include?(name)
|
18
24
|
end
|
19
25
|
|
20
26
|
def on_call(mod, _, loc, *)
|
21
|
-
|
27
|
+
store_location(loc) if mod == 'FactoryBot'
|
22
28
|
end
|
23
29
|
|
24
30
|
def on_command_call(mod, _, loc, *)
|
25
|
-
|
31
|
+
store_location(loc) if mod == 'FactoryBot'
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_comment(text, *)
|
35
|
+
return unless /sloth:(?<directive>disable|enable)/ =~ text
|
36
|
+
|
37
|
+
directive == 'disable' &&
|
38
|
+
@locations.reject! { |loc| loc.first == lineno } ||
|
39
|
+
(@lines ||= @code.lines)[lineno - 1].match?(/^\s*#/) &&
|
40
|
+
(@disabled = directive != 'enable')
|
26
41
|
end
|
27
42
|
|
28
43
|
def on_fcall(loc, *)
|
29
|
-
|
44
|
+
store_location(loc)
|
30
45
|
end
|
31
46
|
|
32
47
|
def on_vcall(loc, *)
|
33
|
-
|
48
|
+
store_location(loc)
|
34
49
|
end
|
35
50
|
end
|