factory_girl 4.4.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/.yardopts +1 -1
- data/Appraisals +4 -0
- data/{CONTRIBUTION_GUIDELINES.md → CONTRIBUTING.md} +0 -0
- data/GETTING_STARTED.md +47 -31
- data/Gemfile +1 -3
- data/Gemfile.lock +17 -13
- data/NEWS +7 -0
- data/README.md +5 -4
- data/factory_girl.gemspec +3 -2
- data/gemfiles/3.1.gemfile +2 -2
- data/gemfiles/3.1.gemfile.lock +32 -26
- data/gemfiles/3.2.gemfile +2 -2
- data/gemfiles/3.2.gemfile.lock +30 -20
- data/gemfiles/4.0.gemfile +2 -2
- data/gemfiles/4.0.gemfile.lock +37 -35
- data/gemfiles/4.1.gemfile +7 -0
- data/gemfiles/4.1.gemfile.lock +93 -0
- data/lib/factory_girl.rb +3 -18
- data/lib/factory_girl/attribute_assigner.rb +1 -1
- data/lib/factory_girl/definition_proxy.rb +6 -0
- data/lib/factory_girl/find_definitions.rb +1 -1
- data/lib/factory_girl/linter.rb +46 -0
- data/lib/factory_girl/strategy/stub.rb +6 -6
- data/lib/factory_girl/version.rb +1 -1
- data/spec/acceptance/create_list_spec.rb +2 -2
- data/spec/acceptance/initialize_with_spec.rb +7 -7
- data/spec/acceptance/lint_spec.rb +17 -7
- data/spec/acceptance/private_attributes_spec.rb +20 -0
- data/spec/acceptance/transient_attributes_spec.rb +30 -3
- data/spec/factory_girl/definition_proxy_spec.rb +2 -2
- data/spec/factory_girl/strategy/stub_spec.rb +2 -2
- metadata +59 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b66b3ff9ce2ea6a436ba4beb95761498dd26152
|
4
|
+
data.tar.gz: ce844f3fb80089bf0f88fed59de2b5a00aef949d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae8b04a6f0c57e39b6361e48d098b5f91f8f12f01f8ad78e82467f7c6d664fb075ec8f3002ca42815d5d9a3460a70ac7c168dd9afc654d7385d4a705b6a4ae0
|
7
|
+
data.tar.gz: 8dd8a73ad04e9fbc5725959108366f6e9970204f24f0f81e66c65387a09a32c22a094ffde3ff75504c62ca2a9f8efb327d84f81cf954afa75a3026750a6cb10e
|
data/.travis.yml
CHANGED
data/.yardopts
CHANGED
data/Appraisals
CHANGED
File without changes
|
data/GETTING_STARTED.md
CHANGED
@@ -29,7 +29,8 @@ Configure your test suite
|
|
29
29
|
-------------------------
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
#
|
32
|
+
# RSpec
|
33
|
+
# spec/support/factory_girl.rb
|
33
34
|
RSpec.configure do |config|
|
34
35
|
config.include FactoryGirl::Syntax::Methods
|
35
36
|
end
|
@@ -88,11 +89,33 @@ RSpec.configure do |config|
|
|
88
89
|
# additional factory_girl configuration
|
89
90
|
|
90
91
|
config.before(:suite) do
|
91
|
-
|
92
|
+
begin
|
93
|
+
DatabaseCleaner.start
|
94
|
+
FactoryGirl.lint
|
95
|
+
ensure
|
96
|
+
DatabaseCleaner.clean
|
97
|
+
end
|
92
98
|
end
|
93
99
|
end
|
94
100
|
```
|
95
101
|
|
102
|
+
After calling `FactoryGirl.lint`, you'll likely want to clear out the
|
103
|
+
database, as built factories will create associated records. The provided
|
104
|
+
example above uses the database_cleaner gem to clear out the database; be sure
|
105
|
+
to add the gem to your Gemfile under the appropriate groups.
|
106
|
+
|
107
|
+
You can lint factories selectively by passing only factories you want linted:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
factories_to_lint = FactoryGirl.factories.reject do |factory|
|
111
|
+
factory.name =~ /^old_/
|
112
|
+
end
|
113
|
+
|
114
|
+
FactoryGirl.lint factories_to_lint
|
115
|
+
```
|
116
|
+
|
117
|
+
This would lint all factories that aren't prefixed with `old_`.
|
118
|
+
|
96
119
|
Defining factories
|
97
120
|
------------------
|
98
121
|
|
@@ -229,7 +252,7 @@ There may be times where your code can be DRYed up by passing in transient attri
|
|
229
252
|
|
230
253
|
```ruby
|
231
254
|
factory :user do
|
232
|
-
|
255
|
+
transient do
|
233
256
|
rockstar true
|
234
257
|
upcased false
|
235
258
|
end
|
@@ -246,14 +269,14 @@ create(:user, upcased: true).name
|
|
246
269
|
#=> "JOHN DOE - ROCKSTAR"
|
247
270
|
```
|
248
271
|
|
249
|
-
Static and dynamic attributes can be
|
250
|
-
within attributes\_for and won't be set on the model,
|
251
|
-
exists or you attempt to override it.
|
272
|
+
Static and dynamic attributes can be created as transient attributes. Transient
|
273
|
+
attributes will be ignored within attributes\_for and won't be set on the model,
|
274
|
+
even if the attribute exists or you attempt to override it.
|
252
275
|
|
253
|
-
Within factory_girl's dynamic attributes, you can access
|
276
|
+
Within factory_girl's dynamic attributes, you can access transient attributes as
|
254
277
|
you would expect. If you need to access the evaluator in a factory_girl callback,
|
255
278
|
you'll need to declare a second block argument (for the evaluator) and access
|
256
|
-
|
279
|
+
transient attributes from there.
|
257
280
|
|
258
281
|
Associations
|
259
282
|
------------
|
@@ -332,14 +355,14 @@ FactoryGirl.define do
|
|
332
355
|
|
333
356
|
# user_with_posts will create post data after the user has been created
|
334
357
|
factory :user_with_posts do
|
335
|
-
# posts_count is declared as
|
358
|
+
# posts_count is declared as a transient attribute and available in
|
336
359
|
# attributes on the factory, as well as the callback via the evaluator
|
337
|
-
|
360
|
+
transient do
|
338
361
|
posts_count 5
|
339
362
|
end
|
340
363
|
|
341
364
|
# the after(:create) yields two values; the user instance itself and the
|
342
|
-
# evaluator, which stores all values from the factory, including
|
365
|
+
# evaluator, which stores all values from the factory, including transient
|
343
366
|
# attributes; `create_list`'s second argument is the number of records
|
344
367
|
# to create and we make sure the user is associated properly to the post
|
345
368
|
after(:create) do |user, evaluator|
|
@@ -398,7 +421,7 @@ Sequences
|
|
398
421
|
---------
|
399
422
|
|
400
423
|
Unique values in a specific format (for example, e-mail addresses) can be
|
401
|
-
generated using sequences. Sequences are defined by calling sequence in a
|
424
|
+
generated using sequences. Sequences are defined by calling `sequence` in a
|
402
425
|
definition block, and values in a sequence are generated by calling
|
403
426
|
`generate`:
|
404
427
|
|
@@ -865,23 +888,18 @@ end
|
|
865
888
|
sequence(:email) { |n| "person#{n}@example.com" }
|
866
889
|
|
867
890
|
factory :user do
|
868
|
-
|
869
|
-
name "Jane Doe"
|
870
|
-
end
|
871
|
-
|
891
|
+
name "Jane Doe"
|
872
892
|
email
|
893
|
+
|
873
894
|
initialize_with { new(name) }
|
874
895
|
end
|
875
896
|
|
876
897
|
build(:user).name # Jane Doe
|
877
898
|
```
|
878
899
|
|
879
|
-
Notice that I ignored the `name` attribute. If you don't want attributes
|
880
|
-
reassigned after your object has been instantiated, you'll want to `ignore` them.
|
881
|
-
|
882
900
|
Although factory_girl is written to work with ActiveRecord out of the box, it
|
883
|
-
can also work with any Ruby class. For maximum
|
884
|
-
the default initializer builds all instances by calling new on your build class
|
901
|
+
can also work with any Ruby class. For maximum compatibility with ActiveRecord,
|
902
|
+
the default initializer builds all instances by calling `new` on your build class
|
885
903
|
without any arguments. It then calls attribute writer methods to assign all the
|
886
904
|
attribute values. While that works fine for ActiveRecord, it actually doesn't
|
887
905
|
work for almost any other Ruby class.
|
@@ -900,9 +918,7 @@ For example:
|
|
900
918
|
|
901
919
|
```ruby
|
902
920
|
factory :user do
|
903
|
-
|
904
|
-
name "John Doe"
|
905
|
-
end
|
921
|
+
name "John Doe"
|
906
922
|
|
907
923
|
initialize_with { User.build_with_name(name) }
|
908
924
|
end
|
@@ -913,7 +929,7 @@ by calling `attributes`:
|
|
913
929
|
|
914
930
|
```ruby
|
915
931
|
factory :user do
|
916
|
-
|
932
|
+
transient do
|
917
933
|
comments_count 5
|
918
934
|
end
|
919
935
|
|
@@ -924,7 +940,7 @@ end
|
|
924
940
|
```
|
925
941
|
|
926
942
|
This will build a hash of all attributes to be passed to `new`. It won't
|
927
|
-
include
|
943
|
+
include transient attributes, but everything else defined in the factory will be
|
928
944
|
passed (associations, evalued sequences, etc.)
|
929
945
|
|
930
946
|
You can define `initialize_with` for all factories by including it in the
|
@@ -1115,19 +1131,19 @@ throughout your test suite. If you're using RSpec, it's as simple as adding a
|
|
1115
1131
|
`before(:suite)` and `after(:suite)`:
|
1116
1132
|
|
1117
1133
|
```ruby
|
1134
|
+
factory_girl_results = {}
|
1118
1135
|
config.before(:suite) do
|
1119
|
-
@factory_girl_results = {}
|
1120
1136
|
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
|
1121
1137
|
factory_name = payload[:name]
|
1122
1138
|
strategy_name = payload[:strategy]
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1139
|
+
factory_girl_results[factory_name] ||= {}
|
1140
|
+
factory_girl_results[factory_name][strategy_name] ||= 0
|
1141
|
+
factory_girl_results[factory_name][strategy_name] += 1
|
1126
1142
|
end
|
1127
1143
|
end
|
1128
1144
|
|
1129
1145
|
config.after(:suite) do
|
1130
|
-
puts
|
1146
|
+
puts factory_girl_results
|
1131
1147
|
end
|
1132
1148
|
```
|
1133
1149
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
factory_girl (4.
|
4
|
+
factory_girl (4.5.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
activemodel (4.0.0)
|
11
11
|
activesupport (= 4.0.0)
|
@@ -22,10 +22,11 @@ GEM
|
|
22
22
|
multi_json (~> 1.3)
|
23
23
|
thread_safe (~> 0.1)
|
24
24
|
tzinfo (~> 0.3.37)
|
25
|
-
appraisal (0.
|
25
|
+
appraisal (1.0.0)
|
26
26
|
bundler
|
27
27
|
rake
|
28
|
-
|
28
|
+
thor (>= 0.14.0)
|
29
|
+
arel (4.0.2)
|
29
30
|
aruba (0.5.3)
|
30
31
|
childprocess (>= 0.3.6)
|
31
32
|
cucumber (>= 1.1.1)
|
@@ -37,25 +38,27 @@ GEM
|
|
37
38
|
builder (3.1.4)
|
38
39
|
childprocess (0.3.9)
|
39
40
|
ffi (~> 1.0, >= 1.0.11)
|
40
|
-
cucumber (1.
|
41
|
+
cucumber (1.3.15)
|
41
42
|
builder (>= 2.1.2)
|
42
43
|
diff-lcs (>= 1.1.3)
|
43
|
-
gherkin (~> 2.
|
44
|
-
multi_json (
|
44
|
+
gherkin (~> 2.12)
|
45
|
+
multi_json (>= 1.7.5, < 2.0)
|
46
|
+
multi_test (>= 0.1.1)
|
45
47
|
diff-lcs (1.1.3)
|
46
48
|
ffi (1.9.0)
|
47
49
|
ffi (1.9.0-java)
|
48
|
-
gherkin (2.
|
50
|
+
gherkin (2.12.2)
|
49
51
|
multi_json (~> 1.3)
|
50
|
-
gherkin (2.
|
52
|
+
gherkin (2.12.2-java)
|
51
53
|
multi_json (~> 1.3)
|
52
54
|
i18n (0.6.4)
|
53
55
|
metaclass (0.0.1)
|
54
56
|
minitest (4.7.5)
|
55
57
|
mocha (0.14.0)
|
56
58
|
metaclass (~> 0.0.1)
|
57
|
-
multi_json (1.
|
58
|
-
|
59
|
+
multi_json (1.10.1)
|
60
|
+
multi_test (0.1.1)
|
61
|
+
rake (10.3.2)
|
59
62
|
rspec (2.12.0)
|
60
63
|
rspec-core (~> 2.12.0)
|
61
64
|
rspec-expectations (~> 2.12.0)
|
@@ -69,6 +72,7 @@ GEM
|
|
69
72
|
simplecov-html (~> 0.7.1)
|
70
73
|
simplecov-html (0.7.1)
|
71
74
|
sqlite3 (1.3.8)
|
75
|
+
thor (0.19.1)
|
72
76
|
thread_safe (0.1.2)
|
73
77
|
atomic
|
74
78
|
thread_safe (0.1.2-java)
|
@@ -83,10 +87,10 @@ PLATFORMS
|
|
83
87
|
|
84
88
|
DEPENDENCIES
|
85
89
|
activerecord (>= 3.0.0)
|
86
|
-
appraisal (~> 0.
|
90
|
+
appraisal (~> 1.0.0)
|
87
91
|
aruba
|
88
92
|
bourne
|
89
|
-
cucumber (~> 1.
|
93
|
+
cucumber (~> 1.3.15)
|
90
94
|
factory_girl!
|
91
95
|
mocha (>= 0.12.8)
|
92
96
|
rspec (~> 2.12.0)
|
data/NEWS
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
4.5.0 (October 17, 2014)
|
2
|
+
Improve FactoryGirl.lint by including exception and message in output
|
3
|
+
Allow selective linting
|
4
|
+
Use more explicit #public_send when doing attribute assignment
|
5
|
+
Improve documentation around FactoryGirl.lint and initialize_with
|
6
|
+
Deprecate #ignore in favor of #transient
|
7
|
+
|
1
8
|
4.4.0 (February 10, 2014)
|
2
9
|
Add FactoryGirl.lint
|
3
10
|
Fix memory leak in duplicate traits
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Documentation
|
|
10
10
|
|
11
11
|
You should find the documentation for your version of factory_girl on [Rubygems](https://rubygems.org/gems/factory_girl).
|
12
12
|
|
13
|
-
See [GETTING_STARTED]
|
13
|
+
See [GETTING_STARTED] for information on defining and using factories.
|
14
14
|
|
15
15
|
Install
|
16
16
|
--------
|
@@ -29,8 +29,7 @@ Supported Ruby versions
|
|
29
29
|
-----------------------
|
30
30
|
|
31
31
|
The factory_girl 3.x+ series supports MRI Ruby 1.9. Additionally, factory_girl
|
32
|
-
3.6+ supports JRuby 1.6.7.2+ while running in 1.9 mode. See
|
33
|
-
[GETTING_STARTED](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md)
|
32
|
+
3.6+ supports JRuby 1.6.7.2+ while running in 1.9 mode. See [GETTING_STARTED]
|
34
33
|
for more information on configuring the JRuby environment.
|
35
34
|
|
36
35
|
For versions of Ruby prior to 1.9, please use factory_girl 2.x.
|
@@ -43,10 +42,12 @@ More Information
|
|
43
42
|
* [Issues](https://github.com/thoughtbot/factory_girl/issues)
|
44
43
|
* [GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS](http://robots.thoughtbot.com/)
|
45
44
|
|
45
|
+
[GETTING_STARTED]: http://rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md
|
46
|
+
|
46
47
|
Contributing
|
47
48
|
------------
|
48
49
|
|
49
|
-
Please see
|
50
|
+
Please see [CONTRIBUTING.md](https://github.com/thoughtbot/factory_girl/blob/master/CONTRIBUTING.md).
|
50
51
|
|
51
52
|
Credits
|
52
53
|
-------
|
data/factory_girl.gemspec
CHANGED
@@ -24,13 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency("activesupport", ">= 3.0.0")
|
25
25
|
|
26
26
|
s.add_development_dependency("rspec", "~> 2.12.0")
|
27
|
-
s.add_development_dependency("cucumber", "~> 1.
|
27
|
+
s.add_development_dependency("cucumber", "~> 1.3.15")
|
28
28
|
s.add_development_dependency("timecop")
|
29
29
|
s.add_development_dependency("simplecov")
|
30
30
|
s.add_development_dependency("aruba")
|
31
31
|
s.add_development_dependency("mocha", ">= 0.12.8")
|
32
32
|
s.add_development_dependency("bourne")
|
33
|
-
s.add_development_dependency("appraisal", "~> 0.
|
33
|
+
s.add_development_dependency("appraisal", "~> 1.0.0")
|
34
|
+
s.add_development_dependency("activerecord", ">= 3.0.0")
|
34
35
|
|
35
36
|
if RUBY_PLATFORM == "java"
|
36
37
|
s.add_development_dependency("activerecord-jdbcsqlite3-adapter")
|
data/gemfiles/3.1.gemfile
CHANGED
data/gemfiles/3.1.gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
factory_girl (4.
|
4
|
+
factory_girl (4.5.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
activemodel (3.1.12)
|
11
11
|
activesupport (= 3.1.12)
|
@@ -18,37 +18,41 @@ GEM
|
|
18
18
|
tzinfo (~> 0.3.29)
|
19
19
|
activesupport (3.1.12)
|
20
20
|
multi_json (~> 1.0)
|
21
|
-
appraisal (0.
|
21
|
+
appraisal (1.0.0)
|
22
22
|
bundler
|
23
23
|
rake
|
24
|
+
thor (>= 0.14.0)
|
24
25
|
arel (2.2.3)
|
25
26
|
aruba (0.5.3)
|
26
27
|
childprocess (>= 0.3.6)
|
27
28
|
cucumber (>= 1.1.1)
|
28
29
|
rspec-expectations (>= 2.7.0)
|
29
|
-
bourne (1.
|
30
|
-
mocha (
|
30
|
+
bourne (1.5.0)
|
31
|
+
mocha (>= 0.13.2, < 0.15)
|
31
32
|
builder (3.0.4)
|
32
33
|
childprocess (0.3.9)
|
33
34
|
ffi (~> 1.0, >= 1.0.11)
|
34
|
-
cucumber (1.
|
35
|
+
cucumber (1.3.15)
|
35
36
|
builder (>= 2.1.2)
|
36
37
|
diff-lcs (>= 1.1.3)
|
37
|
-
gherkin (~> 2.
|
38
|
-
multi_json (
|
38
|
+
gherkin (~> 2.12)
|
39
|
+
multi_json (>= 1.7.5, < 2.0)
|
40
|
+
multi_test (>= 0.1.1)
|
39
41
|
diff-lcs (1.1.3)
|
40
|
-
|
41
|
-
ffi (1.9.
|
42
|
-
|
42
|
+
docile (1.1.3)
|
43
|
+
ffi (1.9.3)
|
44
|
+
ffi (1.9.3-java)
|
45
|
+
gherkin (2.12.2)
|
43
46
|
multi_json (~> 1.3)
|
44
|
-
gherkin (2.
|
47
|
+
gherkin (2.12.2-java)
|
45
48
|
multi_json (~> 1.3)
|
46
|
-
i18n (0.6.
|
47
|
-
metaclass (0.0.
|
48
|
-
mocha (0.
|
49
|
+
i18n (0.6.9)
|
50
|
+
metaclass (0.0.4)
|
51
|
+
mocha (0.14.0)
|
49
52
|
metaclass (~> 0.0.1)
|
50
|
-
multi_json (1.
|
51
|
-
|
53
|
+
multi_json (1.10.1)
|
54
|
+
multi_test (0.1.1)
|
55
|
+
rake (10.3.2)
|
52
56
|
rspec (2.12.0)
|
53
57
|
rspec-core (~> 2.12.0)
|
54
58
|
rspec-expectations (~> 2.12.0)
|
@@ -57,14 +61,16 @@ GEM
|
|
57
61
|
rspec-expectations (2.12.1)
|
58
62
|
diff-lcs (~> 1.1.3)
|
59
63
|
rspec-mocks (2.12.2)
|
60
|
-
simplecov (0.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
simplecov (0.8.2)
|
65
|
+
docile (~> 1.1.0)
|
66
|
+
multi_json
|
67
|
+
simplecov-html (~> 0.8.0)
|
68
|
+
simplecov-html (0.8.0)
|
64
69
|
sqlite3 (1.3.8)
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
thor (0.19.1)
|
71
|
+
timecop (0.7.1)
|
72
|
+
tzinfo (0.3.39)
|
73
|
+
yard (0.8.7.3)
|
68
74
|
|
69
75
|
PLATFORMS
|
70
76
|
java
|
@@ -72,10 +78,10 @@ PLATFORMS
|
|
72
78
|
|
73
79
|
DEPENDENCIES
|
74
80
|
activerecord (~> 3.1.12)
|
75
|
-
appraisal (~> 0.
|
81
|
+
appraisal (~> 1.0.0)
|
76
82
|
aruba
|
77
83
|
bourne
|
78
|
-
cucumber (~> 1.
|
84
|
+
cucumber (~> 1.3.15)
|
79
85
|
factory_girl!
|
80
86
|
mocha (>= 0.12.8)
|
81
87
|
rspec (~> 2.12.0)
|