factory_girl 2.0.0.rc1 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/GETTING_STARTED.md +51 -8
- data/README.md +9 -5
- data/features/support/test.db +0 -0
- data/lib/factory_girl/definition_proxy.rb +6 -4
- data/lib/factory_girl/version.rb +1 -1
- data/spec/factory_girl/definition_proxy_spec.rb +5 -0
- metadata +12 -12
data/GETTING_STARTED.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
Getting Started
|
2
2
|
===============
|
3
3
|
|
4
|
+
Update Your Gemfile
|
5
|
+
-------------------
|
6
|
+
|
7
|
+
If you're using Rails, you'll need to upgrade `factory_girl_rails` to the latest RC:
|
8
|
+
|
9
|
+
gem "factory_girl_rails", "~> 1.1.rc1"
|
10
|
+
|
11
|
+
If you're *not* using Rails, you'll just have to change the required version of `factory_girl`:
|
12
|
+
|
13
|
+
gem "factory_girl", "~> 2.0.0.rc1"
|
14
|
+
|
15
|
+
Once your Gemfile is updated, you'll want to update your bundle.
|
16
|
+
|
4
17
|
Defining factories
|
5
18
|
------------------
|
6
19
|
|
@@ -77,6 +90,14 @@ If repeating "FactoryGirl" is too verbose for you, you can mix the syntax method
|
|
77
90
|
include Factory::Syntax::Methods
|
78
91
|
end
|
79
92
|
|
93
|
+
This would allow you to write:
|
94
|
+
|
95
|
+
describe User, "#full_name" do
|
96
|
+
subject { create(:user, :first_name => "John", :last_name => "Doe") }
|
97
|
+
|
98
|
+
its(:full_name) { should == "John Doe" }
|
99
|
+
end
|
100
|
+
|
80
101
|
Lazy Attributes
|
81
102
|
---------------
|
82
103
|
|
@@ -85,6 +106,33 @@ Most factory attributes can be added using static values that are evaluated when
|
|
85
106
|
factory :user do
|
86
107
|
# ...
|
87
108
|
activation_code { User.generate_activation_code }
|
109
|
+
date_of_birth { 21.years.ago }
|
110
|
+
end
|
111
|
+
|
112
|
+
Aliases
|
113
|
+
-------
|
114
|
+
|
115
|
+
Aliases allow you to use named associations more easily.
|
116
|
+
|
117
|
+
factory :user, :aliases => [:author, :commenter] do
|
118
|
+
first_name "John"
|
119
|
+
last_name "Doe"
|
120
|
+
date_of_birth { 18.years.ago }
|
121
|
+
end
|
122
|
+
|
123
|
+
factory :post do
|
124
|
+
author
|
125
|
+
# instead of
|
126
|
+
# association :author, :factory => :user
|
127
|
+
title "How to read a book effectively"
|
128
|
+
body "There are five steps involved."
|
129
|
+
end
|
130
|
+
|
131
|
+
factory :comment do
|
132
|
+
commenter
|
133
|
+
# instead of
|
134
|
+
# association :commenter, :factory => :user
|
135
|
+
body "Great article!"
|
88
136
|
end
|
89
137
|
|
90
138
|
Dependent Attributes
|
@@ -157,10 +205,6 @@ You can also assign the parent explicitly:
|
|
157
205
|
approved true
|
158
206
|
end
|
159
207
|
|
160
|
-
approved_post = FactoryGirl.create(:approved_post)
|
161
|
-
approved_post.title # => 'A title'
|
162
|
-
approved_post.approved # => true
|
163
|
-
|
164
208
|
As mentioned above, it's good practice to define a basic factory for each class with only the attributes required to create it. Then, create more specific factories that inherit from this basic parent. Factory definitions are still code, so keep them DRY.
|
165
209
|
|
166
210
|
Sequences
|
@@ -231,12 +275,12 @@ Examples:
|
|
231
275
|
after_build { |user| generate_hashed_password(user) }
|
232
276
|
end
|
233
277
|
|
234
|
-
Note that you'll have an instance of the user in the block.
|
278
|
+
Note that you'll have an instance of the user in the block. This can be useful.
|
235
279
|
|
236
280
|
You can also define multiple types of callbacks on the same factory:
|
237
281
|
|
238
282
|
factory :user do
|
239
|
-
after_build { |user| do_something_to(user)
|
283
|
+
after_build { |user| do_something_to(user) }
|
240
284
|
after_create { |user| do_something_else_to(user) }
|
241
285
|
end
|
242
286
|
|
@@ -244,7 +288,7 @@ Factories can also define any number of the same kind of callback. These callba
|
|
244
288
|
|
245
289
|
factory :user do
|
246
290
|
after_create { this_runs_first }
|
247
|
-
after_create { then_this
|
291
|
+
after_create { then_this }
|
248
292
|
end
|
249
293
|
|
250
294
|
Calling FactoryGirl.create will invoke both after_build and after_create callbacks.
|
@@ -281,4 +325,3 @@ Users' tastes for syntax vary dramatically, but most users are looking for a com
|
|
281
325
|
end
|
282
326
|
|
283
327
|
User.make(:name => 'Johnny')
|
284
|
-
|
data/README.md
CHANGED
@@ -13,13 +13,17 @@ You should find the documentation for your version of factory_girl on [Rubygems]
|
|
13
13
|
|
14
14
|
See [GETTING_STARTED.md](http://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md) for information on defining and using factories.
|
15
15
|
|
16
|
-
|
16
|
+
Install
|
17
17
|
--------
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
```shell
|
20
|
+
gem install factory_girl
|
21
|
+
```
|
22
|
+
or add the following line to Gemfile:
|
23
|
+
```ruby
|
24
|
+
gem 'factory_girl'
|
25
|
+
```
|
26
|
+
and run `bundle install` from your shell.
|
23
27
|
|
24
28
|
More Information
|
25
29
|
----------------
|
data/features/support/test.db
CHANGED
Binary file
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module FactoryGirl
|
2
2
|
class DefinitionProxy
|
3
|
-
|
4
|
-
|
3
|
+
UNPROXIED_METHODS = %w(__send__ nil? send object_id extend instance_eval initialize block_given? raise)
|
4
|
+
|
5
|
+
(instance_methods + private_instance_methods).each do |method|
|
6
|
+
undef_method(method) unless UNPROXIED_METHODS.include?(method)
|
5
7
|
end
|
6
8
|
|
7
9
|
attr_reader :child_factories
|
@@ -56,7 +58,7 @@ module FactoryGirl
|
|
56
58
|
# add_attribute :name, 'Billy Idol'
|
57
59
|
# end
|
58
60
|
#
|
59
|
-
# are
|
61
|
+
# are equivalent.
|
60
62
|
#
|
61
63
|
# If no argument or block is given, factory_girl will look for a sequence
|
62
64
|
# or association with the same name. This means that:
|
@@ -73,7 +75,7 @@ module FactoryGirl
|
|
73
75
|
# account
|
74
76
|
# end
|
75
77
|
#
|
76
|
-
# are
|
78
|
+
# are equivalent.
|
77
79
|
def method_missing(name, *args, &block)
|
78
80
|
if args.empty? && block.nil?
|
79
81
|
@factory.define_attribute(Attribute::Implicit.new(name))
|
data/lib/factory_girl/version.rb
CHANGED
@@ -37,6 +37,11 @@ describe FactoryGirl::DefinitionProxy do
|
|
37
37
|
}.should raise_error(FactoryGirl::AttributeDefinitionError)
|
38
38
|
end
|
39
39
|
|
40
|
+
it "should add an attribute with a built-in private method" do
|
41
|
+
subject.instance_eval { sleep(0.1) }
|
42
|
+
factory.attributes.map { |attribute| attribute.name }.should == [:sleep]
|
43
|
+
end
|
44
|
+
|
40
45
|
describe "child factories" do
|
41
46
|
its(:child_factories) { should == [] }
|
42
47
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_girl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424081
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 2.0.0.
|
11
|
+
- 2
|
12
|
+
version: 2.0.0.rc2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Joe Ferris
|
@@ -17,12 +17,13 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-07-05 00:00:00 -04:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: rcov
|
25
25
|
prerelease: false
|
26
|
+
type: :development
|
26
27
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
28
|
none: false
|
28
29
|
requirements:
|
@@ -32,11 +33,11 @@ dependencies:
|
|
32
33
|
segments:
|
33
34
|
- 0
|
34
35
|
version: "0"
|
35
|
-
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
39
|
prerelease: false
|
40
|
+
type: :development
|
40
41
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
42
|
none: false
|
42
43
|
requirements:
|
@@ -46,11 +47,11 @@ dependencies:
|
|
46
47
|
segments:
|
47
48
|
- 0
|
48
49
|
version: "0"
|
49
|
-
type: :development
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
name: cucumber
|
53
53
|
prerelease: false
|
54
|
+
type: :development
|
54
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
56
|
none: false
|
56
57
|
requirements:
|
@@ -60,11 +61,11 @@ dependencies:
|
|
60
61
|
segments:
|
61
62
|
- 0
|
62
63
|
version: "0"
|
63
|
-
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
66
|
name: activerecord
|
67
67
|
prerelease: false
|
68
|
+
type: :development
|
68
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
70
|
none: false
|
70
71
|
requirements:
|
@@ -76,11 +77,11 @@ dependencies:
|
|
76
77
|
- 3
|
77
78
|
- 5
|
78
79
|
version: 2.3.5
|
79
|
-
type: :development
|
80
80
|
version_requirements: *id004
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: activerecord
|
83
83
|
prerelease: false
|
84
|
+
type: :development
|
84
85
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
86
|
none: false
|
86
87
|
requirements:
|
@@ -94,11 +95,11 @@ dependencies:
|
|
94
95
|
- beta
|
95
96
|
- 3
|
96
97
|
version: 3.0.0.beta3
|
97
|
-
type: :development
|
98
98
|
version_requirements: *id005
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: rr
|
101
101
|
prerelease: false
|
102
|
+
type: :development
|
102
103
|
requirement: &id006 !ruby/object:Gem::Requirement
|
103
104
|
none: false
|
104
105
|
requirements:
|
@@ -108,11 +109,11 @@ dependencies:
|
|
108
109
|
segments:
|
109
110
|
- 0
|
110
111
|
version: "0"
|
111
|
-
type: :development
|
112
112
|
version_requirements: *id006
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: sqlite3
|
115
115
|
prerelease: false
|
116
|
+
type: :development
|
116
117
|
requirement: &id007 !ruby/object:Gem::Requirement
|
117
118
|
none: false
|
118
119
|
requirements:
|
@@ -122,7 +123,6 @@ dependencies:
|
|
122
123
|
segments:
|
123
124
|
- 0
|
124
125
|
version: "0"
|
125
|
-
type: :development
|
126
126
|
version_requirements: *id007
|
127
127
|
description: |-
|
128
128
|
factory_girl provides a framework and DSL for defining and
|
@@ -253,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
253
|
requirements: []
|
254
254
|
|
255
255
|
rubyforge_project:
|
256
|
-
rubygems_version: 1.6.
|
256
|
+
rubygems_version: 1.6.1
|
257
257
|
signing_key:
|
258
258
|
specification_version: 3
|
259
259
|
summary: factory_girl provides a framework and DSL for defining and using model instance factories.
|