fluent_fixtures 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -1
- data/History.md +10 -1
- data/lib/fluent_fixtures/factory.rb +33 -0
- data/lib/fluent_fixtures.rb +2 -2
- data/spec/fluent_fixtures/factory_spec.rb +51 -0
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4af7da2d10d611a8705da13607ced285f95c6220
|
4
|
+
data.tar.gz: 45b92115603fa459a00b1c2750735b5c5851731f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 740b6475a410d1bed9ae2aa58577a89558e80d91e97be222b8a4bb66cb34b61b948105b6ebb3526325a30e89b6350c261ffe7274e0e08e537b5236eedddc9efe
|
7
|
+
data.tar.gz: 98b968f86142ca86dc0ba0d5dad1c78ff86a61081b72323b17eb8751b07b858bfd5eafe782fabad683e14c9422de2477230c30f8c46639b6a9040b1daf78f976
|
checksums.yaml.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
��j�� B �@�a�*iO2�A�Hs�t:���=CRn�]���2�>�8��Jֻ
|
2
|
+
������r���X������ja���]��A�����'D��y�<
|
data/History.md
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
+
## v0.3.0 [2016-11-26] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
Enhancements:
|
4
|
+
|
5
|
+
- Make the factory Enumerable and add a #generator method.
|
6
|
+
|
7
|
+
|
1
8
|
## v0.2.0 [2016-10-28] Michael Granger <ged@FaerieMUD.org>
|
2
9
|
|
3
10
|
Bugfixes:
|
11
|
+
|
4
12
|
- Fix the way #create and #instance handle their arguments. Arguments are
|
5
13
|
now iterated over and used to set attributes instead of just being
|
6
|
-
|
14
|
+
discarded.
|
7
15
|
|
8
16
|
|
9
17
|
## v0.1.0 [2016-10-28] Michael Granger <ged@FaerieMUD.org>
|
10
18
|
|
11
19
|
New feature:
|
20
|
+
|
12
21
|
- Add an after-save hook and a declaration for it.
|
13
22
|
|
14
23
|
|
@@ -8,11 +8,15 @@ require 'fluent_fixtures' unless defined?( FluentFixtures )
|
|
8
8
|
# The fluent fixture monadic factory class.
|
9
9
|
class FluentFixtures::Factory
|
10
10
|
extend Loggability
|
11
|
+
include Enumerable
|
11
12
|
|
12
13
|
|
13
14
|
# The methods to look for to save new instances when #create is called
|
14
15
|
CREATE_METHODS = %i[ save_changes save ]
|
15
16
|
|
17
|
+
# The default limit for generators
|
18
|
+
DEFAULT_GENERATOR_LIMIT = 10_000
|
19
|
+
|
16
20
|
|
17
21
|
# Loggability API -- log to the FluentFixtures logger
|
18
22
|
log_to :fluent_fixtures
|
@@ -121,6 +125,35 @@ class FluentFixtures::Factory
|
|
121
125
|
end
|
122
126
|
|
123
127
|
|
128
|
+
### Iterate over DEFAULT_GENERATOR_LIMIT instances of the fixtured object, yielding
|
129
|
+
### each new instance if a block is provided. If no block is provided, returns an
|
130
|
+
### Enumerator.
|
131
|
+
def each( &block )
|
132
|
+
return self.generator unless block
|
133
|
+
return self.generator.each( &block )
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
### Return an infinite generator for unsaved instances of the fixtured object.
|
138
|
+
def generator( create: false, limit: DEFAULT_GENERATOR_LIMIT )
|
139
|
+
return Enumerator.new( limit || Float::INFINITY ) do |yielder|
|
140
|
+
count = 0
|
141
|
+
loop do
|
142
|
+
break if limit && count >= limit
|
143
|
+
obj = if create
|
144
|
+
self.create
|
145
|
+
else
|
146
|
+
self.instance
|
147
|
+
end
|
148
|
+
|
149
|
+
yielder.yield( obj )
|
150
|
+
|
151
|
+
count += 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
124
157
|
### Return a human-readable representation of the object suitable for debugging.
|
125
158
|
def inspect
|
126
159
|
decorator_description = self.decorators.map( &:first ).join( ' + ' )
|
data/lib/fluent_fixtures.rb
CHANGED
@@ -11,10 +11,10 @@ module FluentFixtures
|
|
11
11
|
|
12
12
|
|
13
13
|
# Package version
|
14
|
-
VERSION = '0.
|
14
|
+
VERSION = '0.3.0'
|
15
15
|
|
16
16
|
# Version control revision
|
17
|
-
REVISION = %q$Revision:
|
17
|
+
REVISION = %q$Revision: 5b362f519048 $
|
18
18
|
|
19
19
|
|
20
20
|
# Loggability API -- set up a named logger
|
@@ -293,6 +293,57 @@ describe FluentFixtures::Factory do
|
|
293
293
|
end
|
294
294
|
|
295
295
|
|
296
|
+
describe "enumerator/generator" do
|
297
|
+
|
298
|
+
it "is Enumerable" do
|
299
|
+
expect( factory ).to be_an( Enumerable )
|
300
|
+
expect( factory.each ).to be_an( Enumerator )
|
301
|
+
end
|
302
|
+
|
303
|
+
|
304
|
+
it "can create an enumerator (generator) of unsaved instances" do
|
305
|
+
enum = factory.generator
|
306
|
+
|
307
|
+
expect( enum ).to be_a( Enumerator )
|
308
|
+
|
309
|
+
instance = enum.next
|
310
|
+
|
311
|
+
expect( instance ).to be_a( fixtured_class )
|
312
|
+
expect( instance ).to_not be_saved
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
it "can create an enumerator (generator) of saved instances" do
|
317
|
+
enum = factory.generator( create: true )
|
318
|
+
|
319
|
+
expect( enum ).to be_a( Enumerator )
|
320
|
+
|
321
|
+
instance = enum.next
|
322
|
+
|
323
|
+
expect( instance ).to be_a( fixtured_class )
|
324
|
+
expect( instance ).to be_saved
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
it "is a limited generator by default" do
|
329
|
+
enum = factory.generator
|
330
|
+
expect( enum.size ).to eq( described_class::DEFAULT_GENERATOR_LIMIT )
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
it "can be limited to a different size" do
|
335
|
+
enum = factory.generator( limit: 5 )
|
336
|
+
expect( enum.size ).to eq( 5 )
|
337
|
+
expect( enum.to_a ).to be_an( Array ).and( have_attributes(length: 5) )
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
it "can be created as an infinite generator" do
|
342
|
+
enum = factory.generator( limit: nil )
|
343
|
+
expect( enum.size ).to eq( Float::INFINITY )
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
296
347
|
|
297
348
|
end
|
298
349
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent_fixtures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
w8aNA5re5+Rt/Vvjxj5AcEnZnZiz5x959NaddQocX32Z1unHw44pzRNUur1GInfW
|
36
36
|
p4vpx2kUSFSAGjtCbDGTNV2AH8w9OU4xEmNz8c5lyoA=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2016-
|
38
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: loggability
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
version: '0'
|
238
238
|
requirements: []
|
239
239
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
240
|
+
rubygems_version: 2.6.8
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: FluentFixtures is a toolkit for building testing objects with a fluent interface
|
metadata.gz.sig
CHANGED
Binary file
|