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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 383c2e021a8f95d413975221ad71a812573085d87c344d9092489cd4701c7bcc
4
- data.tar.gz: 855d528ff18cfa4e02645fd6eb7a24b65e170918ba759454ccd06bc5c7e14574
3
+ metadata.gz: 90ab135111ffaf75e4c4e76bb988f18ba65a4830a651806fa3488055931b730c
4
+ data.tar.gz: 6ced697033d75f2be92a0e4353f4e119a119b3b8d88b6b6ac2981112e819dd70
5
5
  SHA512:
6
- metadata.gz: 791b93263904413b1bbdc11df06f18c5181fe44882a10c1d9b6c114b1eec33ee3222edf6a52fff90af03aead6e9e04dfedcf22e8410687bd8d11edea92203a26
7
- data.tar.gz: 057af3f3d8bba6f971a4f6e18c40ab69a13829973b38b3bf1c73ddb6477104d704d5d24d524cbf6b567c8f2ebf2c4e1a7587161c3e601256efd9bfb843040f85
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: { representative: :blog }`
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
- # # :representative specifies the name of the representative object to be declared. Defaults to nil
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: { representative: :blog, items: %i[article], instance: :blog_instance }
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[blog_bp.representative_node.name] } # the representative object
60
- # let(:article) { blog_instance[:article] } # the item objects
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
- { representative: definition }
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
- representative_name = definition[:representative]
91
+ result_name = definition[:result]
92
92
  item_names = definition[:items] || []
93
93
  instance = definition[:instance] || :"#{source}_instance"
94
94
 
95
- if representative_name && !representative_name.is_a?(Symbol)
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 representative_name
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 do |name|
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 representative object to be declared using RSpec's <code>let</code>.
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: { representative: :blog, items: %i[article] }
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 => { representative: name, items: }
151
+ let_blueprint_instantiate strategy, source => { result: name, items: }
158
152
  end
159
153
  end
160
154
  end
@@ -3,7 +3,7 @@
3
3
  module FactoryBot
4
4
  module Blueprint
5
5
  module RSpec
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  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.1.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-22 00:00:00.000000000 Z
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.1.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.1.0
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec-core
29
29
  requirement: !ruby/object:Gem::Requirement