factory_girl 4.7.0 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa9eb22350ba005f4e5f9a78f10e5dd825035c21
4
- data.tar.gz: 2dcd957723bd03f85b6dbc4a674f031873a29a90
3
+ metadata.gz: b54b15d2754297ebbbe0bfae279af379d149cb14
4
+ data.tar.gz: e1704ba19386de1e4f10949b5239e5b8bb7374b7
5
5
  SHA512:
6
- metadata.gz: c3b3e8264c3284d727289be55a71a8f641b801e5610f9261e3caa5d35894fba887d8d23e518e61562751ea25d4d2fcb4a704a0d2132d18e7a0f5fadfedc474df
7
- data.tar.gz: 2bab54b8012900039840a4259c4c5cb98378a312f899530825b4743de4bb1c9d344920cb1073a63e057b7e99b19e06c75c001d1f53fb7ba3c559310b48f9b42b
6
+ metadata.gz: 084c3630e60c5bb99fd839e840c42d0012d647e4f3dd76b2737f979013d09740877aee5900130f59beca69cef1f76cd7a78613edc3d18c43e3879d2d52808af7
7
+ data.tar.gz: 073011ae6b9398b2b3961374181b5b1ec32711a96b1989bf0bb563b7df26f566442312cf9d64ce0e5824f5a9d835c6f3193b61982a0cec9f5dd72b29b6dc42c3
@@ -1,9 +1,10 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
- - 2.1.0
5
- - 2.2.2
6
- - 2.3.0
4
+ - 2.1.9
5
+ - 2.2.5
6
+ - 2.3.1
7
+ - ruby-head
7
8
  - jruby-19mode
8
9
  - rbx-2
9
10
  before_install:
@@ -20,17 +21,18 @@ gemfile:
20
21
  - gemfiles/5.0.gemfile
21
22
  matrix:
22
23
  fast_finish: true
23
- allow_failures:
24
- - rvm: jruby-19mode
25
- gemfile: gemfiles/5.0.gemfile
24
+ exclude:
26
25
  - rvm: 1.9.3
27
26
  gemfile: gemfiles/5.0.gemfile
28
27
  - rvm: 2.0.0
29
28
  gemfile: gemfiles/5.0.gemfile
30
- - rvm: 2.1.0
29
+ - rvm: 2.1.9
31
30
  gemfile: gemfiles/5.0.gemfile
32
- - rvm: rbx-2
31
+ allow_failures:
32
+ - rvm: ruby-head
33
+ - rvm: jruby-19mode
33
34
  gemfile: gemfiles/5.0.gemfile
35
+ - rvm: rbx-2
34
36
  branches:
35
37
  only:
36
38
  - master
data/Appraisals CHANGED
@@ -15,5 +15,5 @@ appraise '4.2' do
15
15
  end
16
16
 
17
17
  appraise '5.0' do
18
- gem 'activerecord', "~> 5.0.0.beta2"
18
+ gem 'activerecord', "~> 5.0.0"
19
19
  end
@@ -20,15 +20,25 @@ Here are some ways *you* can contribute:
20
20
  [issues]: https://github.com/thoughtbot/factory_girl/issues
21
21
 
22
22
  ## Submitting an Issue
23
- We use the [GitHub issue tracker][issues] to track bugs and features. Before
24
- submitting a bug report or feature request, check to make sure it hasn't
25
- already been submitted. When submitting a bug report, please include a [Gist][]
26
- that includes a stack trace and any details that may be necessary to reproduce
27
- the bug, including your gem version, Ruby version, and operating system.
28
- Ideally, a bug report should include a pull request with failing specs.
23
+
24
+ * We use the [GitHub issue tracker][issues] to track bugs and features.
25
+ * Before submitting a bug report or feature request, check to make sure it hasn't
26
+ already been submitted.
27
+ * When submitting a bug report, please include a [Gist][] that includes a stack
28
+ trace and any details that may be necessary to reproduce the bug, including
29
+ your gem version, Ruby version, and operating system. Ideally, a bug report
30
+ should include a pull request with failing specs.
29
31
 
30
32
  [gist]: https://gist.github.com/
31
33
 
34
+ ## Cleaning up issues
35
+
36
+ * Issues that have no response from the submitter will be closed after 30 days.
37
+ * Issues will be closed once they're assumed to be fixed or answered. If the
38
+ maintainer is wrong, it can be opened again.
39
+ * If your issue is closed by mistake, please understand and explain the issue.
40
+ We will happily reopen the issue.
41
+
32
42
  ## Submitting a Pull Request
33
43
  1. [Fork][fork] the [official repository][repo].
34
44
  2. [Create a topic branch.][branch]
@@ -38,6 +48,8 @@ Ideally, a bug report should include a pull request with failing specs.
38
48
 
39
49
  ## Notes
40
50
  * Please add tests if you changed code. Contributions without tests won't be accepted.
51
+ * If you don't know how to add tests, please put in a PR and leave a comment
52
+ asking for help. We love helping!
41
53
  * Please don't update the Gem version.
42
54
 
43
55
  [repo]: https://github.com/thoughtbot/factory_girl/tree/master
@@ -28,8 +28,9 @@ Once your Gemfile is updated, you'll want to update your bundle.
28
28
  Configure your test suite
29
29
  -------------------------
30
30
 
31
- ```ruby
32
31
  # RSpec
32
+
33
+ ```ruby
33
34
  # spec/support/factory_girl.rb
34
35
  RSpec.configure do |config|
35
36
  config.include FactoryGirl::Syntax::Methods
@@ -43,38 +44,56 @@ RSpec.configure do |config|
43
44
  FactoryGirl.find_definitions
44
45
  end
45
46
  end
47
+ ```
46
48
 
47
- Remember to require the above file in your spec_helper since the support folder isn't eagerly loaded
49
+ Remember to require the above file in your rails_helper since the support folder isn't eagerly loaded
48
50
 
49
51
  ```ruby
50
52
  require 'support/factory_girl'
51
53
  ```
52
54
 
53
55
  # Test::Unit
56
+
57
+ ```ruby
54
58
  class Test::Unit::TestCase
55
59
  include FactoryGirl::Syntax::Methods
56
60
  end
61
+ ```
57
62
 
58
63
  # Cucumber
64
+
65
+ ```ruby
59
66
  # env.rb (Rails example location - RAILS_ROOT/features/support/env.rb)
60
67
  World(FactoryGirl::Syntax::Methods)
68
+ ```
61
69
 
62
70
  # Spinach
71
+
72
+ ```ruby
63
73
  class Spinach::FeatureSteps
64
74
  include FactoryGirl::Syntax::Methods
65
75
  end
76
+ ```
66
77
 
67
78
  # Minitest
79
+
80
+ ```ruby
68
81
  class Minitest::Unit::TestCase
69
82
  include FactoryGirl::Syntax::Methods
70
83
  end
84
+ ```
71
85
 
72
86
  # Minitest::Spec
87
+
88
+ ```ruby
73
89
  class Minitest::Spec
74
90
  include FactoryGirl::Syntax::Methods
75
91
  end
92
+ ```
76
93
 
77
94
  # minitest-rails
95
+
96
+ ```ruby
78
97
  class ActiveSupport::TestCase
79
98
  include FactoryGirl::Syntax::Methods
80
99
  end
@@ -151,13 +170,13 @@ user.first_name
151
170
  # => "Joe"
152
171
  ```
153
172
 
154
- Lazy Attributes
155
- ---------------
173
+ Dynamic Attributes
174
+ ------------------
156
175
 
157
176
  Most factory attributes can be added using static values that are evaluated when
158
177
  the factory is defined, but some attributes (such as associations and other
159
178
  attributes that must be dynamically generated) will need values assigned each
160
- time an instance is generated. These "lazy" attributes can be added by passing a
179
+ time an instance is generated. These "dynamic" attributes can be added by passing a
161
180
  block instead of a parameter:
162
181
 
163
182
  ```ruby
@@ -179,7 +198,7 @@ end
179
198
 
180
199
  Aliases
181
200
  -------
182
- FactoryGirl allows you to define aliases to existing factories to make them easier to re-use. This could come in handy when, for example, your Post object has a author attribute that actually refers to an instance of a User class. While normally FactoryGirl can infer the factory name from the association name, in this case it will look for a author factory in vain. So, alias your user factory so it can be used under alias names.
201
+ factory_girl allows you to define aliases to existing factories to make them easier to re-use. This could come in handy when, for example, your Post object has an author attribute that actually refers to an instance of a User class. While normally factory_girl can infer the factory name from the association name, in this case it will look for a author factory in vain. So, alias your user factory so it can be used under alias names.
183
202
 
184
203
  ```ruby
185
204
  factory :user, aliases: [:author, :commenter] do
@@ -207,7 +226,8 @@ end
207
226
  Dependent Attributes
208
227
  --------------------
209
228
 
210
- Attributes can be based on the values of other attributes using the evaluator that is yielded to lazy attribute blocks:
229
+ Attributes can be based on the values of other attributes using the evaluator
230
+ that is yielded to dynamic attribute blocks:
211
231
 
212
232
  ```ruby
213
233
  factory :user do
@@ -269,6 +289,42 @@ end
269
289
 
270
290
  ```
271
291
 
292
+ Inheritance
293
+ -----------
294
+
295
+ You can easily create multiple factories for the same class without repeating common attributes by nesting factories:
296
+
297
+ ```ruby
298
+ factory :post do
299
+ title "A title"
300
+
301
+ factory :approved_post do
302
+ approved true
303
+ end
304
+ end
305
+
306
+ approved_post = create(:approved_post)
307
+ approved_post.title # => "A title"
308
+ approved_post.approved # => true
309
+ ```
310
+
311
+ You can also assign the parent explicitly:
312
+
313
+ ```ruby
314
+ factory :post do
315
+ title "A title"
316
+ end
317
+
318
+ factory :approved_post, parent: :post do
319
+ approved true
320
+ end
321
+ ```
322
+
323
+ As mentioned above, it's good practice to define a basic factory for each class
324
+ with only the attributes required to create it. Then, create more specific
325
+ factories that inherit from this basic parent. Factory definitions are still
326
+ code, so keep them DRY.
327
+
272
328
  Associations
273
329
  ------------
274
330
 
@@ -372,13 +428,13 @@ create(:user_with_posts).posts.length # 5
372
428
  create(:user_with_posts, posts_count: 15).posts.length # 15
373
429
  ```
374
430
 
375
- Generating data for a `has_and_belongs_to_many` relationship is very similar
376
- to the above `has_many` relationship, with a small change, you need to pass an
377
- array of objects to the model's pluralized attribute name rather than a single
431
+ Generating data for a `has_and_belongs_to_many` relationship is very similar
432
+ to the above `has_many` relationship, with a small change, you need to pass an
433
+ array of objects to the model's pluralized attribute name rather than a single
378
434
  object to the singular version of the attribute name.
379
435
 
380
436
  Here's an example with two models that are related via
381
- `has_and_belongs_to_many`:
437
+ `has_and_belongs_to_many`:
382
438
 
383
439
  ```ruby
384
440
  FactoryGirl.define do
@@ -393,7 +449,7 @@ FactoryGirl.define do
393
449
  factory :profile do
394
450
  name "John Doe"
395
451
 
396
- # profile_with_languages will create language data after the profile has
452
+ # profile_with_languages will create language data after the profile has
397
453
  # been created
398
454
  factory :profile_with_languages do
399
455
  # languages_count is declared as an ignored attribute and available in
@@ -402,10 +458,10 @@ FactoryGirl.define do
402
458
  languages_count 5
403
459
  end
404
460
 
405
- # the after(:create) yields two values; the profile instance itself and
406
- # the evaluator, which stores all values from the factory, including
407
- # ignored attributes; `create_list`'s second argument is the number of
408
- # records to create and we make sure the profile is associated properly
461
+ # the after(:create) yields two values; the profile instance itself and
462
+ # the evaluator, which stores all values from the factory, including
463
+ # ignored attributes; `create_list`'s second argument is the number of
464
+ # records to create and we make sure the profile is associated properly
409
465
  # to the language
410
466
  after(:create) do |profile, evaluator|
411
467
  create_list(:language, evaluator.languages_count, profiles: [profile])
@@ -423,42 +479,6 @@ create(:profile_with_languages).languages.length # 5
423
479
  create(:profile_with_languages, languages_count: 15).languages.length # 15
424
480
  ```
425
481
 
426
- Inheritance
427
- -----------
428
-
429
- You can easily create multiple factories for the same class without repeating common attributes by nesting factories:
430
-
431
- ```ruby
432
- factory :post do
433
- title "A title"
434
-
435
- factory :approved_post do
436
- approved true
437
- end
438
- end
439
-
440
- approved_post = create(:approved_post)
441
- approved_post.title # => "A title"
442
- approved_post.approved # => true
443
- ```
444
-
445
- You can also assign the parent explicitly:
446
-
447
- ```ruby
448
- factory :post do
449
- title "A title"
450
- end
451
-
452
- factory :approved_post, parent: :post do
453
- approved true
454
- end
455
- ```
456
-
457
- As mentioned above, it's good practice to define a basic factory for each class
458
- with only the attributes required to create it. Then, create more specific
459
- factories that inherit from this basic parent. Factory definitions are still
460
- code, so keep them DRY.
461
-
462
482
  Sequences
463
483
  ---------
464
484
 
@@ -482,19 +502,19 @@ generate :email
482
502
  # => "person2@example.com"
483
503
  ```
484
504
 
485
- Sequences can be used as attributes:
505
+ Sequences can be used in dynamic attributes:
486
506
 
487
507
  ```ruby
488
- factory :user do
489
- email
508
+ factory :invite do
509
+ invitee { generate(:email) }
490
510
  end
491
511
  ```
492
512
 
493
- Or in lazy attributes:
513
+ Or as implicit attributes:
494
514
 
495
515
  ```ruby
496
- factory :invite do
497
- invitee { generate(:email) }
516
+ factory :user do
517
+ email # Same as `email { generate(:email) }`
498
518
  end
499
519
  ```
500
520
 
@@ -729,21 +749,37 @@ end
729
749
  create(:post).author
730
750
  ```
731
751
 
732
- Finally, traits can be used within other traits to mix in their attributes.
752
+ Traits can be used within other traits to mix in their attributes.
733
753
 
734
754
  ```ruby
735
- FactoryGirl.define do
736
- factory :order do
737
- trait :completed do
738
- completed_at { 3.days.ago }
755
+ factory :order do
756
+ trait :completed do
757
+ completed_at { 3.days.ago }
758
+ end
759
+
760
+ trait :refunded do
761
+ completed
762
+ refunded_at { 1.day.ago }
763
+ end
764
+ end
765
+ ```
766
+
767
+ Finally, traits can accept transient attributes.
768
+
769
+ ```ruby
770
+ factory :invoice do
771
+ trait :with_amount do
772
+ transient do
773
+ amount 1
739
774
  end
740
775
 
741
- trait :refunded do
742
- completed
743
- refunded_at { 1.day.ago }
776
+ after(:create) do |invoice, evaluator|
777
+ create :line_item, invoice: invoice, amount: evaluator.amount
744
778
  end
745
779
  end
746
780
  end
781
+
782
+ create :invoice, :with_amount, amount: 2
747
783
  ```
748
784
 
749
785
  Callbacks
@@ -901,6 +937,12 @@ To set the attributes for each of the factories, you can pass in a hash as you n
901
937
  twenty_year_olds = build_list(:user, 25, date_of_birth: 20.years.ago)
902
938
  ```
903
939
 
940
+ `build_stubbed_list` will give you fully stubbed out instances:
941
+
942
+ ```ruby
943
+ stubbed_users = build_stubbed_list(:user, 25) # array of stubbed users
944
+ ```
945
+
904
946
  There's also a set of `*_pair` methods for creating two records at a time:
905
947
 
906
948
  ```ruby
@@ -908,6 +950,12 @@ built_users = build_pair(:user) # array of two built users
908
950
  created_users = create_pair(:user) # array of two created users
909
951
  ```
910
952
 
953
+ If you need multiple attribute hashes, `attributes_for_list` will generate them:
954
+
955
+ ```ruby
956
+ users_attrs = attributes_for_list(:user, 25) # array of attribute hashes
957
+ ```
958
+
911
959
  Linting Factories
912
960
  -----------------
913
961
 
@@ -968,12 +1016,12 @@ FactoryGirl.lint factories_to_lint
968
1016
 
969
1017
  This would lint all factories that aren't prefixed with `old_`.
970
1018
 
971
- Traits can also be linted. This option verifies that each
972
- and every trait of a factory generates a valid object on its own.
1019
+ Traits can also be linted. This option verifies that each
1020
+ and every trait of a factory generates a valid object on its own.
973
1021
  This is turned on by passing `traits: true` to the `lint` method:
974
1022
 
975
1023
  ```ruby
976
- FactoryGirl.lint traits:true
1024
+ FactoryGirl.lint traits: true
977
1025
  ```
978
1026
 
979
1027
  This can also be combined with other arguments:
@@ -1276,7 +1324,7 @@ FactoryGirl.define do
1276
1324
  name 'United States'
1277
1325
  association :location_group, factory: :north_america
1278
1326
  end
1279
-
1327
+
1280
1328
  factory :north_america, class: LocationGroup do
1281
1329
  name 'North America'
1282
1330
  end
@@ -1,35 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (4.7.0)
4
+ factory_girl (4.8.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (4.2.5.1)
11
- activesupport (= 4.2.5.1)
12
- builder (~> 3.1)
13
- activerecord (4.2.5.1)
14
- activemodel (= 4.2.5.1)
15
- activesupport (= 4.2.5.1)
16
- arel (~> 6.0)
17
- activerecord-jdbc-adapter (1.3.19)
10
+ activemodel (5.0.0.1)
11
+ activesupport (= 5.0.0.1)
12
+ activerecord (5.0.0.1)
13
+ activemodel (= 5.0.0.1)
14
+ activesupport (= 5.0.0.1)
15
+ arel (~> 7.0)
16
+ activerecord-jdbc-adapter (1.3.21)
18
17
  activerecord (>= 2.2)
19
- activerecord-jdbcsqlite3-adapter (1.3.19)
20
- activerecord-jdbc-adapter (~> 1.3.19)
18
+ activerecord-jdbcsqlite3-adapter (1.3.21)
19
+ activerecord-jdbc-adapter (~> 1.3.21)
21
20
  jdbc-sqlite3 (>= 3.7.2, < 3.9)
22
- activesupport (4.2.5.1)
21
+ activesupport (5.0.0.1)
22
+ concurrent-ruby (~> 1.0, >= 1.0.2)
23
23
  i18n (~> 0.7)
24
- json (~> 1.7, >= 1.7.7)
25
24
  minitest (~> 5.1)
26
- thread_safe (~> 0.3, >= 0.3.4)
27
25
  tzinfo (~> 1.1)
28
26
  appraisal (2.1.0)
29
27
  bundler
30
28
  rake
31
29
  thor (>= 0.14.0)
32
- arel (6.0.3)
30
+ arel (7.1.4)
33
31
  aruba (0.13.0)
34
32
  childprocess (~> 0.5.6)
35
33
  contracts (~> 0.9)
@@ -42,6 +40,8 @@ GEM
42
40
  builder (3.2.2)
43
41
  childprocess (0.5.9)
44
42
  ffi (~> 1.0, >= 1.0.11)
43
+ concurrent-ruby (1.0.2)
44
+ concurrent-ruby (1.0.2-java)
45
45
  contracts (0.13.0)
46
46
  cucumber (1.3.20)
47
47
  builder (>= 2.1.2)
@@ -62,7 +62,7 @@ GEM
62
62
  json (1.8.3)
63
63
  json (1.8.3-java)
64
64
  metaclass (0.0.4)
65
- minitest (5.8.4)
65
+ minitest (5.9.1)
66
66
  mocha (1.1.0)
67
67
  metaclass (~> 0.0.1)
68
68
  multi_json (1.11.2)
@@ -89,7 +89,7 @@ GEM
89
89
  json (~> 1.8)
90
90
  simplecov-html (~> 0.10.0)
91
91
  simplecov-html (0.10.0)
92
- sqlite3 (1.3.11)
92
+ sqlite3 (1.3.12)
93
93
  thor (0.19.1)
94
94
  thread_safe (0.3.5)
95
95
  thread_safe (0.3.5-java)
@@ -120,4 +120,4 @@ DEPENDENCIES
120
120
  yard
121
121
 
122
122
  BUNDLED WITH
123
- 1.11.2
123
+ 1.13.6