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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cefc242e547927b9e8805b2dd4be60905f4dd5e484a5b42da6699e3c104879e8
4
- data.tar.gz: 60c06cc54a40a35b4a72850d636510af0883071760fd88b5587091e1866de261
3
+ metadata.gz: 3550aaf57e03aa0da8d68264bab3c4a0a17ed264995859f34cc641e7e376b51b
4
+ data.tar.gz: d947f5e3533b24b7740d509b5e9b8f3a832a6c535eb81f859ba7c562127c3e5a
5
5
  SHA512:
6
- metadata.gz: c96fcd9841cd70fc952f6f503bd2e84024a2bf786fd132805f0badff7b5208f720be9cc36a73981d77f65fa932e256d7b4ecf2c08e59425ce811e10c61f2813a
7
- data.tar.gz: 885c2928964f3dff1e041a4fa09b3c85a13a452e3168a6985754b0ec6fae01c1cc550001f76808451d02ee477bdcb82b1d2c10dd82576f95b1555b2eab325dcb
6
+ metadata.gz: e9abcbc30c854da1ec58f4ab292ab6ed9a851dcbd11bd00291b2902bdec14ec79c21145033c2a984b7243831dd27b426bf5e33f6e9d22272d673a9ff2f61dd97
7
+ data.tar.gz: '03280bc6477e646583c5af49d46e8bacbf611387181c3e0625e007c019170b697151a78fbd1698a859358a512f483a9949f3b6b27006fe92fc85fd10ccb2b149'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.2.0] - 2023-05-16
4
+
5
+ ### Added
6
+
7
+ - Added support for magic comments `# sloth:disable`, `# sloth:enable`
8
+
3
9
  ## [1.1.0] - 2023-05-16
4
10
 
5
11
  ### Added
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
- @locations << loc if loc.instance_of?(Array) && mod == 'FactoryBot'
27
+ store_location(loc) if mod == 'FactoryBot'
22
28
  end
23
29
 
24
30
  def on_command_call(mod, _, loc, *)
25
- @locations << loc if loc.instance_of?(Array) && mod == 'FactoryBot'
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
- @locations << loc if loc.instance_of?(Array)
44
+ store_location(loc)
30
45
  end
31
46
 
32
47
  def on_vcall(loc, *)
33
- @locations << loc if loc.instance_of?(Array)
48
+ store_location(loc)
34
49
  end
35
50
  end
@@ -1,3 +1,3 @@
1
1
  module FactorySloth
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_sloth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller