jeffperrin-object_mother 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ require 'object_mother/factory'
2
+
3
+ if defined? Rails.configuration
4
+ Rails.configuration.after_initialize do
5
+ path = File.join(RAILS_ROOT, 'test', 'object_mother')
6
+ Dir[File.join(path, '*.rb')].each do |file|
7
+ require file
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ module ObjectMother
2
+ class Factory
3
+ @@index = 0
4
+ def self.spawn
5
+ raise 'No create method specified'
6
+ end
7
+ def self.populate(model)
8
+ raise 'No populate method specified for ' + model.to_s
9
+ end
10
+ def self.to_hash(model)
11
+ raise 'No to_hash method specified'
12
+ end
13
+ def self.unique(val)
14
+ @@index += 1
15
+ val.to_s + @@index.to_s
16
+ end
17
+ def self.unique_email(val)
18
+ user, domain = val.split('@')
19
+ unique(user) + '@' + domain
20
+ end
21
+ def self.create
22
+ obj = spawn
23
+ populate(obj)
24
+ yield obj if block_given?
25
+ obj
26
+ end
27
+ def self.create!(&block)
28
+ obj = create(&block)
29
+ obj.save!
30
+ obj
31
+ end
32
+ def self.create_as_hash(&block)
33
+ obj = create(&block)
34
+ to_hash obj
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeffperrin-object_mother
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Perrin
@@ -21,8 +21,11 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files: []
23
23
 
24
- files: []
25
-
24
+ files:
25
+ - lib
26
+ - lib/object_mother
27
+ - lib/object_mother.rb
28
+ - lib/object_mother/factory.rb
26
29
  has_rdoc: true
27
30
  homepage: http://github.com/jeffperrin/object_mother
28
31
  post_install_message: