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 +4 -4
- data/lib/fixture_kit/adapters/minitest_adapter.rb +11 -5
- data/lib/fixture_kit/adapters/rspec_adapter.rb +10 -5
- data/lib/fixture_kit/cache.rb +1 -1
- data/lib/fixture_kit/definition.rb +20 -1
- data/lib/fixture_kit/file_cache.rb +0 -10
- data/lib/fixture_kit/version.rb +1 -1
- data/lib/fixture_kit.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2addefdcd1d783d80888f69edb6953f8d6432471864bd1dafa915705a67ce317
|
|
4
|
+
data.tar.gz: fded508a51904f238bb5befffd3e3f9132e91010cb3ba74cdf159e0e40cefc67
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
13
|
-
|
|
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 =
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
11
|
-
example =
|
|
10
|
+
group = example_group
|
|
11
|
+
example = group.example { block.call(self) }
|
|
12
12
|
succeeded =
|
|
13
13
|
begin
|
|
14
|
-
example.run(
|
|
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
|
-
|
|
31
|
-
|
|
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
|
[],
|
data/lib/fixture_kit/cache.rb
CHANGED
|
@@ -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:
|
|
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)
|
data/lib/fixture_kit/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2026-08-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|