factory_bot-blueprint-rspec 0.1.0 → 0.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 +4 -4
- data/lib/factory_bot/blueprint/rspec/driver.rb +13 -19
- data/lib/factory_bot/blueprint/rspec/version.rb +1 -1
- 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: 90ab135111ffaf75e4c4e76bb988f18ba65a4830a651806fa3488055931b730c
|
4
|
+
data.tar.gz: 6ced697033d75f2be92a0e4353f4e119a119b3b8d88b6b6ac2981112e819dd70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d5c135992273852319396b86bd7bf9e7a843d7882378ec8c9b024fed1d36624f248be87b9840baf3d3b1498db12fef2e0208539d34a73e6a8a7e210151e7e0b
|
7
|
+
data.tar.gz: 0f630406055469c8b5c917c1f294224f3915dc78f016e5ee92aed62efd25c4e55c4765dbd609f4dc9a78dd7ec79ee1ad8da276d67d009b3110fd4e6c9bfad2f2
|
@@ -41,7 +41,7 @@ module FactoryBot
|
|
41
41
|
# end
|
42
42
|
#
|
43
43
|
# # Simplest example:
|
44
|
-
# # This is equivalent to `let_blueprint_build blog_bp: {
|
44
|
+
# # This is equivalent to `let_blueprint_build blog_bp: { result: :blog }`
|
45
45
|
# let_blueprint_build blog_bp: :blog
|
46
46
|
#
|
47
47
|
# # Another shorthand example:
|
@@ -49,15 +49,15 @@ module FactoryBot
|
|
49
49
|
# let_blueprint_build blog_bp: %i[blog article]
|
50
50
|
#
|
51
51
|
# # Most flexible example:
|
52
|
-
# # :
|
52
|
+
# # :result specifies the name of the result object to be declared. Defaults to nil
|
53
53
|
# # :items specifies the names of the objects to be declared. Defaults to []
|
54
54
|
# # :instance specifies the name of the instance object to be declared. Defaults to :"#{source}_instance"
|
55
|
-
# let_blueprint_build blog_bp: {
|
55
|
+
# let_blueprint_build blog_bp: { result: :blog, items: %i[article], instance: :blog_instance }
|
56
56
|
#
|
57
57
|
# # Above example will be expanded to:
|
58
58
|
# let(:blog_instance) { ::FactoryBot::Blueprint.build(blog_bp) } # the instance object
|
59
|
-
# let(:blog) { blog_instance[
|
60
|
-
# let(:article) { blog_instance[:article] }
|
59
|
+
# let(:blog) { blog_instance[0] } # the result object
|
60
|
+
# let(:article) { blog_instance[1][:article] } # the item objects
|
61
61
|
# end
|
62
62
|
def let_blueprint_build(**map) = let_blueprint_instantiate(:build, **map)
|
63
63
|
|
@@ -79,7 +79,7 @@ module FactoryBot
|
|
79
79
|
definition =
|
80
80
|
case definition
|
81
81
|
when Symbol
|
82
|
-
{
|
82
|
+
{ result: definition }
|
83
83
|
when Array
|
84
84
|
{ items: definition }
|
85
85
|
when Hash
|
@@ -88,13 +88,11 @@ module FactoryBot
|
|
88
88
|
raise TypeError, "definition must be one of Symbol, Array, Hash"
|
89
89
|
end
|
90
90
|
|
91
|
-
|
91
|
+
result_name = definition[:result]
|
92
92
|
item_names = definition[:items] || []
|
93
93
|
instance = definition[:instance] || :"#{source}_instance"
|
94
94
|
|
95
|
-
if
|
96
|
-
raise TypeError, "representative must be a Symbol"
|
97
|
-
end
|
95
|
+
raise TypeError, "result must be a Symbol" if result_name && !result_name.is_a?(Symbol)
|
98
96
|
if !item_names.is_a?(Array) || !item_names.all? { _1.is_a?(Symbol) }
|
99
97
|
raise TypeError, "items must be an Array of Symbols"
|
100
98
|
end
|
@@ -104,13 +102,9 @@ module FactoryBot
|
|
104
102
|
let(instance) { ::FactoryBot::Blueprint.instantiate(strategy, __send__(source)) }
|
105
103
|
end
|
106
104
|
|
107
|
-
if
|
108
|
-
let(representative_name) { __send__(instance)[__send__(source).representative_node.name] }
|
109
|
-
end
|
105
|
+
let(result_name) { __send__(instance)[0] } if result_name
|
110
106
|
|
111
|
-
item_names.each
|
112
|
-
let(name) { __send__(instance)[name] }
|
113
|
-
end
|
107
|
+
item_names.each { |name| let(name) { __send__(instance)[1][name] } }
|
114
108
|
end
|
115
109
|
end
|
116
110
|
|
@@ -119,7 +113,7 @@ module FactoryBot
|
|
119
113
|
#
|
120
114
|
# This is a shorthand for {#let_blueprint} with {#let_blueprint_build} or {#let_blueprint_create}.
|
121
115
|
# @param name [Symbol]
|
122
|
-
# name of the
|
116
|
+
# name of the result object to be declared using RSpec's <code>let</code>.
|
123
117
|
# It is also used as a name prefix of the blueprint
|
124
118
|
# @param items [Array<Symbol>] names of the objects to be declared using RSpec's <code>let</code>
|
125
119
|
# @param inherit [Boolean] whether to extend the blueprint by <code>super()</code>
|
@@ -145,7 +139,7 @@ module FactoryBot
|
|
145
139
|
# article(title: "Article 3")
|
146
140
|
# end
|
147
141
|
# end
|
148
|
-
# let_blueprint_create blog_blueprint: {
|
142
|
+
# let_blueprint_create blog_blueprint: { result: :blog, items: %i[article] }
|
149
143
|
# end
|
150
144
|
def letbp(name, items = [], inherit: false, strategy: :create, &)
|
151
145
|
raise TypeError, "name must be a Symbol" unless name.is_a?(Symbol)
|
@@ -154,7 +148,7 @@ module FactoryBot
|
|
154
148
|
strategy = nil if inherit
|
155
149
|
|
156
150
|
let_blueprint(source, inherit:, &)
|
157
|
-
let_blueprint_instantiate strategy, source => {
|
151
|
+
let_blueprint_instantiate strategy, source => { result: name, items: }
|
158
152
|
end
|
159
153
|
end
|
160
154
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot-blueprint-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-07-
|
11
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot-blueprint
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|