factory_girl_extensions 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown
CHANGED
@@ -17,7 +17,7 @@ As of version 2.0, factory_girl_extensions now targets the new FactoryGirl 2.0 A
|
|
17
17
|
## Usage
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
require 'factory_girl_extensions'
|
20
|
+
require 'factory_girl_extensions' # This includes custom methods in every Class. See below to customize this.
|
21
21
|
|
22
22
|
FactoryGirl.define do
|
23
23
|
factory :user do
|
@@ -76,6 +76,27 @@ User.generate(:admin, :with_profile, :name => 'Custom name')
|
|
76
76
|
# User.build and User.attributes also support these custom prefix/suffixes.
|
77
77
|
```
|
78
78
|
|
79
|
+
### Extend custom classes with FactoryGirlExtensions
|
80
|
+
|
81
|
+
When you `require "factory_girl_extensions"`, we include custom methods (build/generate/etc) into
|
82
|
+
every class by calling:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
require "factory_girl_extensions/core"
|
86
|
+
|
87
|
+
Class.send :include, FactoryGirlExtensions
|
88
|
+
```
|
89
|
+
|
90
|
+
If you don't want all of your classes to be polluted with these methods (for example, you only want
|
91
|
+
to extend your ActiveRecord::Base classes with these methods), you can simply:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
# don't require factory_girl_extensions! require factory_girl_extensions/core instead.
|
95
|
+
require "factory_girl_extensions/core"
|
96
|
+
|
97
|
+
ActiveRecord::Base.send :extend, FactoryGirlExtensions
|
98
|
+
```
|
99
|
+
|
79
100
|
## Why User.gen instead of FactoryGirl(:user)?
|
80
101
|
|
81
102
|
Personally, I really dislike the `FactoryGirl(:user)` syntax. When you have a lot of
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require "factory_girl_extensions/version"
|
2
|
-
|
3
1
|
module FactoryGirl
|
4
2
|
module Syntax
|
5
3
|
|
@@ -149,3 +147,10 @@ module FactoryGirl
|
|
149
147
|
end
|
150
148
|
end
|
151
149
|
end
|
150
|
+
|
151
|
+
# Alias FactoryGirl::Syntax::ObjectMethods (which is named to be conventional with the official FactoryGirl syntaxes)
|
152
|
+
# to FactoryGirlExtensions so it's easy for users to manually extend custom classes without having to remember the
|
153
|
+
# unintuitive name of the real module. We'll deprecate FactoryGirlExtensions if we get this merged into FactoryGirl.
|
154
|
+
FactoryGirlExtensions = FactoryGirl::Syntax::ObjectMethods
|
155
|
+
|
156
|
+
require "factory_girl_extensions/version"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "factory_girl"
|
2
|
+
require "factory_girl_extensions"
|
3
|
+
|
4
|
+
class Dog
|
5
|
+
attr_accessor :name, :breed, :is_saved
|
6
|
+
|
7
|
+
def save
|
8
|
+
self.is_saved = "Saved via #save"
|
9
|
+
end
|
10
|
+
|
11
|
+
def save!
|
12
|
+
self.is_saved = "Saved via #save!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
FactoryGirl.define do
|
17
|
+
factory :dog do
|
18
|
+
name "Rover"
|
19
|
+
breed "Golden Retriever"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_and_eval_code(code)
|
24
|
+
puts ">> #{code}"
|
25
|
+
puts "=> #{eval(code).inspect}"
|
26
|
+
rescue Exception => ex
|
27
|
+
puts "Exception raised: #{ex.inspect}"
|
28
|
+
end
|
29
|
+
|
30
|
+
print_and_eval_code "Dog.build"
|
31
|
+
print_and_eval_code "Dog.build(:name => 'Spot')"
|
32
|
+
print_and_eval_code "Dog.gen"
|
33
|
+
print_and_eval_code "Dog.gen(:name => 'Spot')"
|
34
|
+
print_and_eval_code "Dog.gen!"
|
35
|
+
print_and_eval_code "Dog.gen!(:name => 'Spot')"
|
36
|
+
print_and_eval_code "Dog.attrs"
|
37
|
+
print_and_eval_code "'a string'.gen"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: factory_girl
|
16
|
-
requirement: &
|
16
|
+
requirement: &8440440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8440440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &8439800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8439800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &8439160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *8439160
|
47
47
|
description: ! "Alternative FactoryGirl API allowing you to build/generate factories
|
48
48
|
\nusing your class constants, eg. User.gen instead of Factory(:user).\n"
|
49
49
|
email: remi@remitaylor.com
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/factory_girl_extensions.rb
|
61
61
|
- lib/factory_girl_extensions/core.rb
|
62
62
|
- lib/factory_girl_extensions/version.rb
|
63
|
+
- samples/dog_sample.rb
|
63
64
|
- spec/factory_girl_extensions_spec.rb
|
64
65
|
homepage: http://github.com/remi/factory_girl_extensions
|
65
66
|
licenses: []
|