fixture_kit 0.18.0 → 0.19.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: f929fa8e3c8ecc52b9c9fdb0bacd2b94042f1cd55d91528427af72bb752f033a
4
- data.tar.gz: 563261390ebdc5cd01dc17b1e6cf1fa3d304a871ff76ffe03ff54935e886940f
3
+ metadata.gz: 2addefdcd1d783d80888f69edb6953f8d6432471864bd1dafa915705a67ce317
4
+ data.tar.gz: fded508a51904f238bb5befffd3e3f9132e91010cb3ba74cdf159e0e40cefc67
5
5
  SHA512:
6
- metadata.gz: db45522c0b30284ef5bb37ece365d899c351d67e01a3a864a9e0b8909a61f0fdf5a3c0afb18352c86c9187a4400ed83c24364ee2e53331273a712dc6ba6d1659
7
- data.tar.gz: 668150429508f1ec34d2c9a82b3610036c3645acd135ebc9894922ea8e08838f619446a38646bca1b0859f1e99b3dc7c7dc72c9241f02317f05fb7084493458d
6
+ metadata.gz: 2f1b4dc03ceb9edf697972849a4da270a8d6760c1885ffd3ddd579b96fd7896c29d0989bf044deb824d95c5bce598fe3fd5a45753dad674696ad312674963dc9
7
+ data.tar.gz: 6d11e943aac3c481c047579c4537782a35003603690e46d8ea23a172e5dbf93a3ae736f38738611a519c6f73d6e3b38516e8172b4c2397345d2ae4e441ddd0cc
@@ -7,15 +7,18 @@ require "active_support/inflector"
7
7
  module FixtureKit
8
8
  class MinitestAdapter < FixtureKit::Adapter
9
9
  TEST_NAME = "fixture kit cache pregeneration"
10
+ TEST_METHOD = :"test_#{TEST_NAME.tr(" ", "_")}"
10
11
 
11
12
  def execute(&block)
12
- test_class = build_test_class
13
- test_method = test_class.test(TEST_NAME) do
13
+ test = test_class.new(TEST_METHOD)
14
+ # Minitest runs a test by sending its name to the instance, so defining it
15
+ # here leaves the reused class untouched and the block dies with the test.
16
+ test.define_singleton_method(TEST_METHOD) do
14
17
  block.call(self)
15
18
  pass
16
19
  end
17
20
 
18
- result = test_class.new(test_method).run
21
+ result = test.run
19
22
  return if result.passed?
20
23
 
21
24
  raise result.failures.first.error
@@ -27,8 +30,11 @@ module FixtureKit
27
30
 
28
31
  private
29
32
 
30
- def build_test_class
31
- Class.new(ActiveSupport::TestCase) do
33
+ # Reused rather than built per generation: including
34
+ # ActiveRecord::TestFixtures appends the class to ActiveSupport's
35
+ # :active_record_fixtures load hooks, and that never shrinks.
36
+ def test_class
37
+ @test_class ||= Class.new(ActiveSupport::TestCase) do
32
38
  ::Minitest::Runnable.runnables.delete(self)
33
39
  include(::ActiveRecord::TestFixtures)
34
40
  end
@@ -7,12 +7,14 @@ module FixtureKit
7
7
  def execute(&block)
8
8
  previous_example = ::RSpec.current_example
9
9
  previous_scope = ::RSpec.current_scope
10
- example_group = build_example_group
11
- example = example_group.example { block.call(self) }
10
+ group = example_group
11
+ example = group.example { block.call(self) }
12
12
  succeeded =
13
13
  begin
14
- example.run(example_group.new, ::RSpec::Core::NullReporter)
14
+ example.run(group.new, ::RSpec::Core::NullReporter)
15
15
  ensure
16
+ # The group is reused, and the example it holds retains this block.
17
+ group.examples.clear
16
18
  ::RSpec.current_example = previous_example
17
19
  ::RSpec.current_scope = previous_scope
18
20
  end
@@ -27,8 +29,11 @@ module FixtureKit
27
29
 
28
30
  private
29
31
 
30
- def build_example_group
31
- ::RSpec::Core::ExampleGroup.subclass(
32
+ # Reused rather than built per generation: rspec-rails includes
33
+ # ActiveRecord::TestFixtures into every group, which appends it to
34
+ # ActiveSupport's :active_record_fixtures load hooks, and that never shrinks.
35
+ def example_group
36
+ @example_group ||= ::RSpec::Core::ExampleGroup.subclass(
32
37
  ::RSpec::Core::ExampleGroup,
33
38
  "FixtureKit",
34
39
  [],
@@ -53,7 +53,7 @@ module FixtureKit
53
53
  FixtureKit.runner.adapter.execute do |context|
54
54
  @content = MemoryCache.new(
55
55
  data: evaluate(FixtureKit.runner.coders, context),
56
- exposed: file_cache.serialize_exposed(fixture.definition.exposed)
56
+ exposed: fixture.definition.exposed
57
57
  )
58
58
  end
59
59
 
@@ -25,12 +25,31 @@ module FixtureKit
25
25
  raise FixtureKit::DuplicateNameError, "Name #{name} already exposed"
26
26
  end
27
27
 
28
- @exposed[name] = record
28
+ @exposed[name] = serialize(name, record)
29
29
  end
30
30
  end
31
31
 
32
32
  private
33
33
 
34
+ def serialize(name, record)
35
+ if record.is_a?(Array)
36
+ record.map { |item| reference(name, item) }
37
+ else
38
+ reference(name, record)
39
+ end
40
+ end
41
+
42
+ def reference(name, record)
43
+ unless record.persisted?
44
+ raise FixtureKit::UnpersistedRecordError,
45
+ "cannot expose #{name.inspect}: the #{record.class} is not persisted. " \
46
+ "Exposed records are captured as class/id pairs when `expose` is called, " \
47
+ "so save the record before exposing it."
48
+ end
49
+
50
+ { record.class => record.id }
51
+ end
52
+
34
53
  def mixin(parent)
35
54
  definition = self
36
55
 
@@ -48,16 +48,6 @@ module FixtureKit
48
48
  File.write(path, JSON.pretty_generate(content))
49
49
  end
50
50
 
51
- def serialize_exposed(exposed)
52
- exposed.each_with_object({}) do |(name, record), hash|
53
- if record.is_a?(Array)
54
- hash[name] = record.map { |record| { record.class => record.id } }
55
- else
56
- hash[name] = { record.class => record.id }
57
- end
58
- end
59
- end
60
-
61
51
  private
62
52
 
63
53
  def coder_for(class_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FixtureKit
4
- VERSION = "0.18.0"
4
+ VERSION = "0.19.0"
5
5
  end
data/lib/fixture_kit.rb CHANGED
@@ -9,6 +9,7 @@ module FixtureKit
9
9
  class FixtureDefinitionNotFound < Error; end
10
10
  class RunnerAlreadyStartedError < Error; end
11
11
  class CircularFixtureInheritance < Error; end
12
+ class UnpersistedRecordError < Error; end
12
13
 
13
14
  autoload :VERSION, File.expand_path("fixture_kit/version", __dir__)
14
15
  autoload :Configuration, File.expand_path("fixture_kit/configuration", __dir__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-07-20 00:00:00.000000000 Z
11
+ date: 2026-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport