factory_bot-blueprint 0.2.0 → 0.4.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 +29 -7
- data/lib/factory_bot/blueprint/version.rb +1 -1
- data/lib/factory_bot/blueprint.rb +11 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0c7f0e3747308e1e3eecd28cbd960aa98b65ae2c08b55b7e6346d1b953b064
|
4
|
+
data.tar.gz: dcc1a57961d57b1ce4f29f8b2f83f659ccfa9ae19781903516b698d75dedbcdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5fb41444b1b0ca831a651deb8a70c7bfd02409b5536a6f5c7367b34abade51463bb03bcc562fc190399f54a493a55564d589d10b3c31ff7207160f5f5da8257
|
7
|
+
data.tar.gz: 784d7af975f12da0a6f576c5dccb3e3ccd121e4dd0826280ec6b9a9cbc2f19df8610c450b34263d0b1252367918584750544ac542ca41e761f4c6ce8ca868d8c
|
@@ -10,16 +10,38 @@ module FactoryBot
|
|
10
10
|
# We would like to minimize these dependencies as much as possible.
|
11
11
|
|
12
12
|
# @!visibility private
|
13
|
-
def respond_to_missing?(
|
14
|
-
|
13
|
+
def respond_to_missing?(name, _)
|
14
|
+
_autocompleted_method_names(name).any? do |method_name|
|
15
|
+
self.class.method_defined?(method_name) || FactoryBot.factories.registered?(method_name)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
|
-
def method_missing(
|
18
|
-
|
19
|
+
def method_missing(name, ...)
|
20
|
+
_autocompleted_method_names(name).each do |method_name|
|
21
|
+
if self.class.method_defined?(method_name)
|
22
|
+
return __send__(method_name, ...)
|
23
|
+
elsif FactoryBot.factories.registered?(method_name)
|
24
|
+
factory = FactoryBot.factories.find(method_name)
|
25
|
+
self.class.add_type(self.class.type_from_factory_bot_factory(method_name, factory))
|
26
|
+
return __send__(method_name, ...)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
raise NoMethodError,
|
31
|
+
"Undefined method `#{name}' for #{self} and cannot be resolved from FactoryBot factories"
|
32
|
+
end
|
19
33
|
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
private
|
35
|
+
|
36
|
+
def _autocompleted_method_names(name)
|
37
|
+
return enum_for(__method__, name) unless block_given?
|
38
|
+
|
39
|
+
@ancestors.reverse_each do |ancestor|
|
40
|
+
ancestor.type.compatible_types.each do |ancestor_type|
|
41
|
+
yield :"#{ancestor_type}_#{name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
yield name
|
23
45
|
end
|
24
46
|
|
25
47
|
class << self
|
@@ -41,33 +41,33 @@ module FactoryBot
|
|
41
41
|
# end
|
42
42
|
#
|
43
43
|
# # Create a set of objects in FactoryBot (with `build` strategy) from the blueprint:
|
44
|
-
#
|
44
|
+
# objects = FactoryBot::Blueprint.build(bp)
|
45
45
|
#
|
46
46
|
# # This behaves as:
|
47
47
|
# objects = {}
|
48
48
|
# objects[:blog] = blog = FactoryBot.build(:blog)
|
49
|
-
# objects[
|
50
|
-
# objects[
|
51
|
-
# objects[
|
52
|
-
# objects[
|
53
|
-
# objects[
|
54
|
-
#
|
49
|
+
# objects[random_anon_sym] = FactoryBot.build(:article, title: "Article 1", blog:)
|
50
|
+
# objects[random_anon_sym] = FactoryBot.build(:article, title: "Article 2", blog:)
|
51
|
+
# objects[random_anon_sym] = article3 = FactoryBot.build(:article, title: "Article 3", blog:)
|
52
|
+
# objects[random_anon_sym] = FactoryBot.build(:comment, name: "John", article: article3)
|
53
|
+
# objects[random_anon_sym] = FactoryBot.build(:comment, name: "Doe", article: article3)
|
54
|
+
# objects[Factrey::Blueprint::Node::RESULT_NAME] = blog
|
55
55
|
def plan(blueprint = nil, ext: nil, &) = Factrey.blueprint(blueprint, ext:, dsl: DSL, &)
|
56
56
|
|
57
|
-
# Create a set of objects
|
57
|
+
# Create a set of objects by <code>build</code> strategy in FactoryBot.
|
58
58
|
# See {.plan} for more details.
|
59
59
|
# @param blueprint [Factrey::Blueprint, nil]
|
60
60
|
# @param ext [Object] an external object that can be accessed using {DSL#ext} in the DSL
|
61
61
|
# @yield Write Blueprint DSL code here
|
62
|
-
# @return [
|
62
|
+
# @return [Hash{Symbol => Object}] the created objects
|
63
63
|
def build(blueprint = nil, ext: nil, &) = instantiate(:build, blueprint, ext:, &)
|
64
64
|
|
65
|
-
# Create a set of objects
|
65
|
+
# Create a set of objects by <code>create</code> strategy in FactoryBot.
|
66
66
|
# See {.plan} for more details.
|
67
67
|
# @param blueprint [Factrey::Blueprint, nil]
|
68
68
|
# @param ext [Object] an external object that can be accessed using {DSL#ext} in the DSL
|
69
69
|
# @yield Write Blueprint DSL code here
|
70
|
-
# @return [
|
70
|
+
# @return [Hash{Symbol => Object}] the created objects
|
71
71
|
def create(blueprint = nil, ext: nil, &) = instantiate(:create, blueprint, ext:, &)
|
72
72
|
|
73
73
|
# @!visibility private
|
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.4.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-08-13 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.4.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.4.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.
|