factory_bot-blueprint 0.4.0 → 0.5.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/factory_bot/blueprint/dsl.rb +4 -4
- data/lib/factory_bot/blueprint/methods.rb +33 -0
- data/lib/factory_bot/blueprint/version.rb +1 -1
- data/lib/factory_bot/blueprint.rb +27 -13
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e01f7a2b8a4f8b2940edd4c7793e941274356fe21fc294acb3afd27c1eacab73
|
4
|
+
data.tar.gz: b57c70a58ea87edbc8d9a66d6a87b16c63051d5d12eec86ce02c26b6ec1339bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e07e0eb13aa6098f34e280b88eeaa4db272432965084da60bd135c481523fadae22edf1bd1678224376ed9ff89b646c3c859f31083e7f05b9b4443a0690e00d
|
7
|
+
data.tar.gz: df80db74e368bea0faa790160ac1d7597163ad45e460bbaa1979d00af5a408fede439efa01dd755387799286031a577459210a8a51662ee59e2f1a9d45d0d02f
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module FactoryBot
|
4
4
|
module Blueprint
|
5
|
-
# A declarative DSL for building {Factrey::Blueprint}.
|
5
|
+
# A declarative DSL for building {https://rubydoc.info/gems/factrey/Factrey/Blueprint Factrey::Blueprint}.
|
6
6
|
# This DSL automatically recognizes factories defined in FactoryBot as types.
|
7
7
|
class DSL < Factrey::DSL
|
8
8
|
# Internals:
|
@@ -64,9 +64,9 @@ module FactoryBot
|
|
64
64
|
Factrey::Blueprint::Type.new(type_name, compatible_types:, auto_references:, &FACTORY)
|
65
65
|
end
|
66
66
|
|
67
|
-
FACTORY = lambda
|
68
|
-
FactoryBot.__send__(context[:
|
69
|
-
|
67
|
+
FACTORY = lambda do |type, context, *args, **kwargs|
|
68
|
+
FactoryBot.__send__(context[:build_strategy], type.name, *args, **kwargs)
|
69
|
+
end
|
70
70
|
|
71
71
|
private_constant :FACTORY
|
72
72
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FactoryBot
|
4
|
+
module Blueprint
|
5
|
+
# This module provides a shortcut to FactoryBot::Blueprint.
|
6
|
+
# @example
|
7
|
+
# # Configure the same way as FactoryBot::Syntax::Methods
|
8
|
+
# RSpec.configure do |config|
|
9
|
+
# config.include FactoryBot::Syntax::Methods
|
10
|
+
# config.include FactoryBot::Blueprint::Methods
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # You can use `bp` in your spec files
|
14
|
+
# RSpec.describe "something" do
|
15
|
+
# before do
|
16
|
+
# bp.create do
|
17
|
+
# blog do
|
18
|
+
# article(title: "Article 1")
|
19
|
+
# article(title: "Article 2")
|
20
|
+
# article(title: "Article 3") do
|
21
|
+
# comment(name: "John")
|
22
|
+
# comment(name: "Doe")
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
module Methods
|
29
|
+
# @return [Class<FactoryBot::Blueprint>]
|
30
|
+
def bp = FactoryBot::Blueprint
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -4,21 +4,25 @@ require "factrey"
|
|
4
4
|
require "factory_bot"
|
5
5
|
require_relative "blueprint/version"
|
6
6
|
require_relative "blueprint/dsl"
|
7
|
+
require_relative "blueprint/methods"
|
7
8
|
|
8
9
|
module FactoryBot
|
9
10
|
# A FactoryBot extension for building structured objects using a declarative DSL.
|
10
|
-
# First we can build (or extend) a creation plan for a set of objects as
|
11
|
+
# First we can build (or extend) a creation plan for a set of objects as
|
12
|
+
# {https://rubydoc.info/gems/factrey/Factrey/Blueprint Factrey::Blueprint},
|
11
13
|
# and then we can create actual objects from it.
|
12
14
|
#
|
13
|
-
# <code>Blueprint</code>s can be built using a declarative DSL provided by a core library called
|
15
|
+
# <code>Blueprint</code>s can be built using a declarative DSL provided by a core library called <code>Factrey</code>.
|
14
16
|
# Each node declaration in the DSL code is automatically correspond to the FactoryBot's factory. For example,
|
15
17
|
# a declaration <code>user(name: 'John')</code> corresponds to <code>FactoryBot.create(:user, name: 'John')</code>.
|
16
18
|
module Blueprint
|
17
19
|
class << self
|
18
|
-
# Entry point to build or extend a {Factrey::Blueprint}.
|
20
|
+
# Entry point to build or extend a {https://rubydoc.info/gems/factrey/Factrey/Blueprint Factrey::Blueprint}.
|
19
21
|
# @param blueprint [Factrey::Blueprint, nil] to extend an existing blueprint
|
20
|
-
# @param ext [Object] an external object that can be accessed using
|
21
|
-
# @yield
|
22
|
+
# @param ext [Object] an external object that can be accessed using <code>DSL#ext</code> in the DSL
|
23
|
+
# @yield
|
24
|
+
# Write Blueprint DSL code here. See {https://rubydoc.info/gems/factrey/Factrey/DSL Factrey::DSL} documents for
|
25
|
+
# more details
|
22
26
|
# @return [Factrey::Blueprint] the built or extended blueprint
|
23
27
|
# @example
|
24
28
|
# # In this example, we have three factories in FactoryBot:
|
@@ -40,7 +44,7 @@ module FactoryBot
|
|
40
44
|
# end
|
41
45
|
# end
|
42
46
|
#
|
43
|
-
# # Create a set of objects in FactoryBot (with `build` strategy) from the blueprint:
|
47
|
+
# # Create a set of objects in FactoryBot (with `build` build strategy) from the blueprint:
|
44
48
|
# objects = FactoryBot::Blueprint.build(bp)
|
45
49
|
#
|
46
50
|
# # This behaves as:
|
@@ -54,27 +58,37 @@ module FactoryBot
|
|
54
58
|
# objects[Factrey::Blueprint::Node::RESULT_NAME] = blog
|
55
59
|
def plan(blueprint = nil, ext: nil, &) = Factrey.blueprint(blueprint, ext:, dsl: DSL, &)
|
56
60
|
|
57
|
-
# Create a set of objects by <code>build</code> strategy in FactoryBot.
|
61
|
+
# Create a set of objects by <code>build</code> build strategy in FactoryBot.
|
58
62
|
# See {.plan} for more details.
|
59
63
|
# @param blueprint [Factrey::Blueprint, nil]
|
60
|
-
# @param ext [Object] an external object that can be accessed using
|
64
|
+
# @param ext [Object] an external object that can be accessed using <code>DSL#ext</code> in the DSL
|
61
65
|
# @yield Write Blueprint DSL code here
|
62
66
|
# @return [Hash{Symbol => Object}] the created objects
|
63
67
|
def build(blueprint = nil, ext: nil, &) = instantiate(:build, blueprint, ext:, &)
|
64
68
|
|
65
|
-
# Create a set of objects by <code>
|
69
|
+
# Create a set of objects by <code>build_stubbed</code> build strategy in FactoryBot.
|
66
70
|
# See {.plan} for more details.
|
67
71
|
# @param blueprint [Factrey::Blueprint, nil]
|
68
|
-
# @param ext [Object] an external object that can be accessed using
|
72
|
+
# @param ext [Object] an external object that can be accessed using <code>DSL#ext</code> in the DSL
|
73
|
+
# @yield Write Blueprint DSL code here
|
74
|
+
# @return [Hash{Symbol => Object}] the created objects
|
75
|
+
def build_stubbed(blueprint = nil, ext: nil, &) = instantiate(:build_stubbed, blueprint, ext:, &)
|
76
|
+
|
77
|
+
# Create a set of objects by <code>create</code> build strategy in FactoryBot.
|
78
|
+
# See {.plan} for more details.
|
79
|
+
# @param blueprint [Factrey::Blueprint, nil]
|
80
|
+
# @param ext [Object] an external object that can be accessed using <code>DSL#ext</code> in the DSL
|
69
81
|
# @yield Write Blueprint DSL code here
|
70
82
|
# @return [Hash{Symbol => Object}] the created objects
|
71
83
|
def create(blueprint = nil, ext: nil, &) = instantiate(:create, blueprint, ext:, &)
|
72
84
|
|
73
85
|
# @!visibility private
|
74
|
-
def instantiate(
|
75
|
-
|
86
|
+
def instantiate(build_strategy, blueprint = nil, ext: nil, &)
|
87
|
+
unless %i[create build build_stubbed].include?(build_strategy)
|
88
|
+
raise ArgumentError, "Unsupported build strategy: #{build_strategy}"
|
89
|
+
end
|
76
90
|
|
77
|
-
plan(blueprint, ext:, &).instantiate(
|
91
|
+
plan(blueprint, ext:, &).instantiate(build_strategy:)
|
78
92
|
end
|
79
93
|
end
|
80
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot-blueprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yubrot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.5.0
|
41
41
|
description: |
|
42
42
|
FactoryBot::Blueprint is a FactoryBot extension for building structured objects using a declarative DSL.
|
43
43
|
On the DSL, the factories defined in FactoryBot can be used without any additional configuration.
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- lib/factory_bot/blueprint.rb
|
53
53
|
- lib/factory_bot/blueprint/dsl.rb
|
54
|
+
- lib/factory_bot/blueprint/methods.rb
|
54
55
|
- lib/factory_bot/blueprint/version.rb
|
55
56
|
homepage: https://github.com/yubrot/factory_bot-blueprint
|
56
57
|
licenses:
|
@@ -68,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
69
|
requirements:
|
69
70
|
- - ">="
|
70
71
|
- !ruby/object:Gem::Version
|
71
|
-
version: 3.
|
72
|
+
version: 3.2.0
|
72
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
74
|
requirements:
|
74
75
|
- - ">="
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
|
-
rubygems_version: 3.5.
|
79
|
+
rubygems_version: 3.5.22
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: FactoryBot extension for building structured objects using a declarative
|