fluent_fixtures 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ require 'fluent_fixtures/dsl'
6
+ require 'faker'
7
+
8
+
9
+ describe FluentFixtures::DSL do
10
+
11
+ let( :collection ) { Module.new {extend FluentFixtures::Collection} }
12
+
13
+ let( :fixtured_class ) do
14
+ Class.new do
15
+ def initialize( params={} )
16
+ @saved = false
17
+ params.each do |name, value|
18
+ self.send( "#{name}=", value )
19
+ end
20
+ end
21
+ attr_accessor :name, :login, :email
22
+ def save; @saved = true; end
23
+ def saved?; @saved; end
24
+ def bizarroify
25
+ self.name = "Bizarro #{self.name}"
26
+ self.email = "bizarro+#{self.email}"
27
+ self.login = "__#{self.login}__"
28
+ self
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+ let!( :fixture_module ) do
35
+ mod = Module.new do
36
+ def self::name ; "UsageTests"; end
37
+ end
38
+ mod.extend( collection )
39
+ mod.fixtured_class( fixtured_class )
40
+ mod.base( :fixture ) do
41
+ self.name ||= Faker::Name.name
42
+ self.login ||= Faker::Internet.user_name
43
+ self.email ||= Faker::Internet.email( self.login )
44
+ end
45
+ mod
46
+ end
47
+
48
+
49
+ it "allows the declaration of decorator blocks" do
50
+ no_email_block = Proc.new { self.email = nil }
51
+ fixture_module.decorator( :with_no_email, &no_email_block )
52
+ no_login_block = Proc.new { self.login = nil }
53
+ fixture_module.decorator( :with_no_login, &no_login_block )
54
+
55
+ expect( fixture_module ).to have_decorator( :with_no_email )
56
+ expect( fixture_module ).to have_decorator( :with_no_login )
57
+
58
+ expect( fixture_module.decorators[:with_no_email] ).to be( no_email_block )
59
+ expect( fixture_module.decorators[:with_no_login] ).to be( no_login_block )
60
+ end
61
+
62
+
63
+ it "can register a creation hook to allow for unusual models" do
64
+ expect {
65
+ fixture_module.before_saving do |obj|
66
+ obj
67
+ end
68
+ }.to change { fixture_module.respond_to?(:call_before_saving) }.
69
+ from( false ).to( true )
70
+ end
71
+
72
+
73
+ it "can declare an alias for an already-declared decorator" do
74
+ fixture_module.decorator( :with_no_email ) { self.email = nil }
75
+ fixture_module.alias_decorator( :emailless, :with_no_email )
76
+
77
+ expect( fixture_module ).to have_decorator( :with_no_email )
78
+ expect( fixture_module ).to have_decorator( :emailless )
79
+ end
80
+
81
+
82
+ it "raises an error when an alias for a non-existent decorator is declared" do
83
+ expect {
84
+ fixture_module.alias_decorator( :an_alias, :nonexistent_decorator )
85
+ }.to raise_error( ScriptError, /undefined decorator.*nonexistent_decorator/ )
86
+ end
87
+
88
+
89
+ it "constructs the factory with the arguments passed to the base fixture" do
90
+ args = { name: 'Phil', login: 'phil', email: 'phil@phil.org' }
91
+
92
+ factory = collection.fixture( args )
93
+
94
+ expect( factory.constructor_args ).to eq([ args ])
95
+ end
96
+
97
+
98
+ it "constructs the factory with a block passed to the base fixture" do
99
+ block = Proc.new { self.tie = true }
100
+
101
+ factory = collection.fixture( &block )
102
+
103
+ expect( factory.constructor_block ).to eq( block )
104
+ end
105
+
106
+
107
+ end
108
+
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ require 'faker'
6
+ require 'fluent_fixtures/factory'
7
+
8
+
9
+ describe FluentFixtures::Factory do
10
+
11
+ let( :collection ) { Module.new {extend FluentFixtures::Collection} }
12
+
13
+ let( :fixtured_class ) do
14
+ Class.new do
15
+ def initialize( params={} )
16
+ @saved = false
17
+ params.each do |name, value|
18
+ self.send( "#{name}=", value )
19
+ end
20
+ yield if block_given?
21
+ end
22
+ attr_accessor :name, :login, :email
23
+ def save; @saved = true; end
24
+ def saved?; @saved; end
25
+ def bizarroify
26
+ self.name = "Bizarro #{self.name}"
27
+ self.email = "bizarro+#{self.email}"
28
+ self.login = "__#{self.login}__"
29
+ self
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ let( :fixture_module ) do
36
+ mod = Module.new
37
+ mod.extend( collection )
38
+ mod.fixtured_class( fixtured_class )
39
+ mod.base( :fixture ) do
40
+ self.name ||= Faker::Name.name
41
+ self.login ||= Faker::Internet.user_name
42
+ self.email ||= Faker::Internet.email( self.login )
43
+ end
44
+ mod
45
+ end
46
+
47
+
48
+ let( :factory ) { described_class.new(fixture_module) }
49
+
50
+
51
+ it "can create an unsaved instance of the fixtured class" do
52
+ object = factory.instance
53
+ expect( object ).to be_a( fixtured_class )
54
+ expect( object ).to_not be_saved
55
+ end
56
+
57
+
58
+ it "can create a saved instance of the fixtured class" do
59
+ object = factory.create
60
+ expect( object ).to be_a( fixtured_class )
61
+ expect( object ).to be_saved
62
+ end
63
+
64
+
65
+ it "applies the base fixture decorator to all instances" do
66
+ object = factory.instance
67
+
68
+ expect( object ).to be_a( fixtured_class )
69
+ expect( object.name ).to_not be_nil
70
+ expect( object.login ).to_not be_nil
71
+ expect( object.email ).to_not be_nil
72
+ end
73
+
74
+
75
+ it "applies named decorators via fluent interface on the factory" do
76
+ fixture_module.decorator( :with_no_email ) { self.email = nil }
77
+ fixture_module.decorator( :with_no_login ) { self.login = nil }
78
+
79
+ object = factory.with_no_email.with_no_login.instance
80
+
81
+ expect( object ).to be_a( fixtured_class )
82
+ expect( object.name ).to_not be_nil
83
+ expect( object.login ).to be_nil
84
+ expect( object.email ).to be_nil
85
+ end
86
+
87
+
88
+ it "forwards constructor arguments to the class's constructor" do
89
+ factory = described_class.new( fixture_module, name: 'Phil', login: 'phil', email: 'phil@phil.org' )
90
+ object = factory.instance
91
+
92
+ expect( object ).to be_a( fixtured_class )
93
+ expect( object.name ).to eq( 'Phil' )
94
+ expect( object.login ).to eq( 'phil' )
95
+ expect( object.email ).to eq( 'phil@phil.org' )
96
+ expect( object ).to_not be_saved
97
+ end
98
+
99
+
100
+ it "forwards a constructor block to the class's constructor" do
101
+ called = false
102
+ factory = described_class.new( fixture_module ) do
103
+ called = true
104
+ end
105
+
106
+ expect { factory.instance }.to change { called }.to( true )
107
+ end
108
+
109
+
110
+ it "executes a block passed to #instance in the context of the new object if it doesn't declare arguments" do
111
+ object = factory.instance do
112
+ self.name = 'Dan'
113
+ self.login = 'danp'
114
+ self.email = 'danp@example.com'
115
+ end
116
+
117
+ expect( object ).to be_a( fixtured_class )
118
+ expect( object.name ).to eq( 'Dan' )
119
+ expect( object.login ).to eq( 'danp' )
120
+ expect( object.email ).to eq( 'danp@example.com' )
121
+ expect( object ).to_not be_saved
122
+ end
123
+
124
+
125
+ it "passes the new object to an #instance block if it accepts arguments" do
126
+ object = factory.instance do |instance|
127
+ instance.name = 'Dan'
128
+ instance.login = 'danp'
129
+ instance.email = 'danp@example.com'
130
+ end
131
+
132
+ expect( object ).to be_a( fixtured_class )
133
+ expect( object.name ).to eq( 'Dan' )
134
+ expect( object.login ).to eq( 'danp' )
135
+ expect( object.email ).to eq( 'danp@example.com' )
136
+ expect( object ).to_not be_saved
137
+ end
138
+
139
+
140
+ it "executes a block passed to #create in the context of the new object" do
141
+ object = factory.create do
142
+ self.name = 'Jenn'
143
+ self.login = 'jennnn'
144
+ self.email = 'jennnn@allthejennifers.org'
145
+ end
146
+
147
+ expect( object ).to be_a( fixtured_class )
148
+ expect( object.name ).to eq( 'Jenn' )
149
+ expect( object.login ).to eq( 'jennnn' )
150
+ expect( object.email ).to eq( 'jennnn@allthejennifers.org' )
151
+ expect( object ).to be_saved
152
+ end
153
+
154
+
155
+ it "passes the new object to a #create block if it accepts arguments" do
156
+ object = factory.create do |instance|
157
+ instance.name = 'Jenn'
158
+ instance.login = 'jennnn'
159
+ instance.email = 'jennnn@allthejennifers.org'
160
+ end
161
+
162
+ expect( object ).to be_a( fixtured_class )
163
+ expect( object.name ).to eq( 'Jenn' )
164
+ expect( object.login ).to eq( 'jennnn' )
165
+ expect( object.email ).to eq( 'jennnn@allthejennifers.org' )
166
+ expect( object ).to be_saved
167
+ end
168
+
169
+
170
+ it "allows ad-hoc decorators that call fluent mutator methods on the new object" do
171
+ object = factory.bizarroify.instance
172
+
173
+ expect( object ).to be_a( fixtured_class )
174
+ expect( object.name ).to start_with( 'Bizarro ')
175
+ expect( object.login ).to match( /\A__.*__\z/ )
176
+ expect( object.email ).to start_with( 'bizarro+' )
177
+ expect( object ).to_not be_saved
178
+ end
179
+
180
+
181
+ it "supports decorators that take one or more arguments" do
182
+ fixture_module.decorator( :with_email ) do |new_email|
183
+ self.email = new_email
184
+ end
185
+
186
+ object = factory.with_email( 'herzepholina@paquisod.org' ).instance
187
+
188
+ expect( object ).to be_a( fixtured_class )
189
+ expect( object.email ).to eq( 'herzepholina@paquisod.org' )
190
+ expect( object ).to_not be_saved
191
+ end
192
+
193
+
194
+ it "calls its fixture module's #call_before_saving method before creating if it implements it" do
195
+ def fixture_module.call_before_saving( instance )
196
+ :not_the_instance
197
+ end
198
+
199
+ result = factory.create
200
+
201
+ expect( result ).to be( :not_the_instance )
202
+ end
203
+
204
+
205
+ it "allows ad-hoc decorators declared as inline blocks" do
206
+ counter = 0
207
+ result = factory.decorated_with do |obj|
208
+ counter += 1
209
+ end
210
+
211
+ 5.times do
212
+ expect {
213
+ result.instance
214
+ }.to change { counter }.by( 1 )
215
+ end
216
+ end
217
+
218
+
219
+ it "raises when asked for an instance if its fixture module doesn't declare a fixtured class" do
220
+ fixmod = Module.new
221
+ fixmod.extend( collection )
222
+ fixmod.base( :no_fixclass_fixture )
223
+
224
+ factory = described_class.new( fixmod )
225
+
226
+ expect {
227
+ factory.instance
228
+ }.to raise_error( ScriptError, /#{Regexp.escape fixmod.inspect}/ )
229
+ end
230
+
231
+
232
+
233
+ end
234
+
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rspec -cfd
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ require 'fluent_fixtures'
6
+
7
+
8
+ describe FluentFixtures do
9
+
10
+ it "has a semver version" do
11
+ expect( described_class::VERSION ).to match( /\A\d+\.\d+\.\d+(-[\p{Alnum}-]+)?/ )
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+ #encoding: utf-8
3
+
4
+ require 'simplecov' if ENV['COVERAGE']
5
+
6
+ require 'rspec'
7
+
8
+ require 'loggability/spechelpers'
9
+
10
+
11
+ ### Mock with RSpec
12
+ RSpec.configure do |config|
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+ config.order = 'random'
16
+ config.mock_with( :rspec ) do |mock|
17
+ mock.syntax = :expect
18
+ end
19
+
20
+ config.include( Loggability::SpecHelpers )
21
+ end
22
+
23
+
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent_fixtures
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Granger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDMDCCAhigAwIBAgIBAjANBgkqhkiG9w0BAQUFADA+MQwwCgYDVQQDDANnZWQx
14
+ GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
15
+ HhcNMTYwNjAyMDE1NTQ2WhcNMTcwNjAyMDE1NTQ2WjA+MQwwCgYDVQQDDANnZWQx
16
+ GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
17
+ ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDb92mkyYwuGBg1oRxt2tkH
18
+ +Uo3LAsaL/APBfSLzy8o3+B3AUHKCjMUaVeBoZdWtMHB75X3VQlvXfZMyBxj59Vo
19
+ cDthr3zdao4HnyrzAIQf7BO5Y8KBwVD+yyXCD/N65TTwqsQnO3ie7U5/9ut1rnNr
20
+ OkOzAscMwkfQxBkXDzjvAWa6UF4c5c9kR/T79iA21kDx9+bUMentU59aCJtUcbxa
21
+ 7kcKJhPEYsk4OdxR9q2dphNMFDQsIdRO8rywX5FRHvcb+qnXC17RvxLHtOjysPtp
22
+ EWsYoZMxyCDJpUqbwoeiM+tAHoz2ABMv3Ahie3Qeb6+MZNAtMmaWfBx3dg2u+/WN
23
+ AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBSZ0hCV
24
+ qoHr122fGKelqffzEQBhszANBgkqhkiG9w0BAQUFAAOCAQEAF2XCzjfTFxkcVvuj
25
+ hhBezFkZnMDYtWezg4QCkR0RHg4sl1LdXjpvvI59SIgD/evD1hOteGKsXqD8t0E4
26
+ OPAWWv/z+JRma72zeYsBZLSDRPIUvBoul6qCpvY0MiWTh496mFwOxT5lvSAUoh+U
27
+ pQ/MQeH/yC6hbGp7IYska6J8T4z5XkYqafYZ3eKQ8H+xPd/z+gYx+jd0PfkWf1Wk
28
+ QQdziL01SKBHf33OAH/p/puCpwS+ZDfgnNx5oMijWbc671UXkrt7zjD0kGakq+9I
29
+ hnfm736z8j1wvWddqf45++gwPpDr1E4zoAq2PgRl/WBNyR0hfoZLpi3TnHu3eC0x
30
+ uALKNA==
31
+ -----END CERTIFICATE-----
32
+ date: 2016-06-02 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: loggability
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.11'
48
+ - !ruby/object:Gem::Dependency
49
+ name: inflecto
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: hoe-mercurial
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ - !ruby/object:Gem::Dependency
77
+ name: hoe-deveiate
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ - !ruby/object:Gem::Dependency
91
+ name: hoe-highline
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ - !ruby/object:Gem::Dependency
105
+ name: rdoc
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.0'
118
+ - !ruby/object:Gem::Dependency
119
+ name: faker
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.6'
132
+ - !ruby/object:Gem::Dependency
133
+ name: simplecov
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.7'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.7'
146
+ - !ruby/object:Gem::Dependency
147
+ name: rdoc-generator-fivefish
148
+ requirement: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.1'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.1'
160
+ - !ruby/object:Gem::Dependency
161
+ name: hoe
162
+ requirement: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.15'
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.15'
174
+ description: |-
175
+ A toolkit for building a collection of composable testing fixtures with a fluent interface.
176
+
177
+ To get started using the library, check out the [Getting Started](GettingStarted_md.html) guide.
178
+ email:
179
+ - ged@FaerieMUD.org
180
+ executables: []
181
+ extensions: []
182
+ extra_rdoc_files:
183
+ - GettingStarted.md
184
+ - History.md
185
+ - LICENSE.txt
186
+ - Manifest.txt
187
+ - README.md
188
+ files:
189
+ - ".document"
190
+ - ".rdoc_options"
191
+ - ".simplecov"
192
+ - ChangeLog
193
+ - GettingStarted.md
194
+ - History.md
195
+ - LICENSE.txt
196
+ - Manifest.txt
197
+ - README.md
198
+ - Rakefile
199
+ - lib/fluent_fixtures.rb
200
+ - lib/fluent_fixtures/collection.rb
201
+ - lib/fluent_fixtures/dsl.rb
202
+ - lib/fluent_fixtures/factory.rb
203
+ - spec/fluent_fixtures/collection_spec.rb
204
+ - spec/fluent_fixtures/dsl_spec.rb
205
+ - spec/fluent_fixtures/factory_spec.rb
206
+ - spec/fluent_fixtures_spec.rb
207
+ - spec/spec_helper.rb
208
+ homepage: http://deveiate.org/projects/fluent_fixtures
209
+ licenses:
210
+ - BSD-3-Clause
211
+ metadata: {}
212
+ post_install_message:
213
+ rdoc_options:
214
+ - "--main"
215
+ - README.md
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: 2.2.0
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ requirements: []
229
+ rubyforge_project:
230
+ rubygems_version: 2.6.2
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: A toolkit for building a collection of composable testing fixtures with a
234
+ fluent interface
235
+ test_files: []