factory_girl 4.5.0 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +25 -5
  3. data/Appraisals +11 -7
  4. data/CONTRIBUTING.md +44 -6
  5. data/GETTING_STARTED.md +175 -59
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +86 -63
  8. data/LICENSE +1 -1
  9. data/NEWS +12 -1
  10. data/README.md +21 -10
  11. data/Rakefile +1 -3
  12. data/factory_girl.gemspec +6 -14
  13. data/gemfiles/3.2.gemfile +4 -1
  14. data/gemfiles/3.2.gemfile.lock +84 -52
  15. data/gemfiles/4.0.gemfile +4 -1
  16. data/gemfiles/4.0.gemfile.lock +75 -49
  17. data/gemfiles/4.1.gemfile +4 -1
  18. data/gemfiles/4.1.gemfile.lock +78 -48
  19. data/gemfiles/4.2.gemfile +10 -0
  20. data/gemfiles/4.2.gemfile.lock +123 -0
  21. data/gemfiles/5.0.gemfile +10 -0
  22. data/gemfiles/5.0.gemfile.lock +126 -0
  23. data/lib/factory_girl.rb +13 -4
  24. data/lib/factory_girl/attribute/dynamic.rb +4 -1
  25. data/lib/factory_girl/attribute_assigner.rb +2 -2
  26. data/lib/factory_girl/configuration.rb +4 -0
  27. data/lib/factory_girl/decorator.rb +2 -2
  28. data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
  29. data/lib/factory_girl/definition_proxy.rb +2 -2
  30. data/lib/factory_girl/evaluator.rb +4 -0
  31. data/lib/factory_girl/factory_runner.rb +7 -1
  32. data/lib/factory_girl/find_definitions.rb +1 -1
  33. data/lib/factory_girl/linter.rb +65 -14
  34. data/lib/factory_girl/strategy/stub.rb +25 -1
  35. data/lib/factory_girl/strategy_syntax_method_registrar.rb +4 -0
  36. data/lib/factory_girl/version.rb +1 -1
  37. metadata +26 -185
  38. data/features/find_definitions.feature +0 -75
  39. data/features/step_definitions/database_steps.rb +0 -9
  40. data/features/step_definitions/factory_girl_steps.rb +0 -36
  41. data/features/support/env.rb +0 -10
  42. data/features/support/factories.rb +0 -16
  43. data/gemfiles/3.1.gemfile +0 -7
  44. data/gemfiles/3.1.gemfile.lock +0 -91
  45. data/spec/acceptance/activesupport_instrumentation_spec.rb +0 -62
  46. data/spec/acceptance/aliases_spec.rb +0 -19
  47. data/spec/acceptance/attribute_aliases_spec.rb +0 -45
  48. data/spec/acceptance/attribute_existing_on_object_spec.rb +0 -68
  49. data/spec/acceptance/attributes_for_spec.rb +0 -97
  50. data/spec/acceptance/attributes_from_instance_spec.rb +0 -53
  51. data/spec/acceptance/attributes_ordered_spec.rb +0 -51
  52. data/spec/acceptance/build_list_spec.rb +0 -56
  53. data/spec/acceptance/build_spec.rb +0 -86
  54. data/spec/acceptance/build_stubbed_spec.rb +0 -161
  55. data/spec/acceptance/callbacks_spec.rb +0 -253
  56. data/spec/acceptance/create_list_spec.rb +0 -97
  57. data/spec/acceptance/create_pair_spec.rb +0 -32
  58. data/spec/acceptance/create_spec.rb +0 -116
  59. data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
  60. data/spec/acceptance/defining_methods_inside_a_factory_spec.rb +0 -17
  61. data/spec/acceptance/definition_camel_string_spec.rb +0 -15
  62. data/spec/acceptance/definition_spec.rb +0 -21
  63. data/spec/acceptance/definition_without_block_spec.rb +0 -15
  64. data/spec/acceptance/global_initialize_with_spec.rb +0 -82
  65. data/spec/acceptance/global_to_create_spec.rb +0 -122
  66. data/spec/acceptance/initialize_with_spec.rb +0 -217
  67. data/spec/acceptance/keyed_by_class_spec.rb +0 -22
  68. data/spec/acceptance/lint_spec.rb +0 -65
  69. data/spec/acceptance/modify_factories_spec.rb +0 -184
  70. data/spec/acceptance/modify_inherited_spec.rb +0 -52
  71. data/spec/acceptance/nested_attributes_spec.rb +0 -32
  72. data/spec/acceptance/overrides_spec.rb +0 -61
  73. data/spec/acceptance/parent_spec.rb +0 -90
  74. data/spec/acceptance/private_attributes_spec.rb +0 -20
  75. data/spec/acceptance/register_strategies_spec.rb +0 -136
  76. data/spec/acceptance/sequence_context_spec.rb +0 -52
  77. data/spec/acceptance/sequence_spec.rb +0 -61
  78. data/spec/acceptance/skip_create_spec.rb +0 -19
  79. data/spec/acceptance/stub_spec.rb +0 -62
  80. data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +0 -51
  81. data/spec/acceptance/traits_spec.rb +0 -727
  82. data/spec/acceptance/transient_attributes_spec.rb +0 -151
  83. data/spec/factory_girl/aliases_spec.rb +0 -31
  84. data/spec/factory_girl/attribute/association_spec.rb +0 -28
  85. data/spec/factory_girl/attribute/dynamic_spec.rb +0 -52
  86. data/spec/factory_girl/attribute/sequence_spec.rb +0 -16
  87. data/spec/factory_girl/attribute/static_spec.rb +0 -19
  88. data/spec/factory_girl/attribute_list_spec.rb +0 -143
  89. data/spec/factory_girl/attribute_spec.rb +0 -16
  90. data/spec/factory_girl/callback_spec.rb +0 -41
  91. data/spec/factory_girl/declaration/implicit_spec.rb +0 -25
  92. data/spec/factory_girl/declaration_list_spec.rb +0 -67
  93. data/spec/factory_girl/definition_proxy_spec.rb +0 -215
  94. data/spec/factory_girl/definition_spec.rb +0 -64
  95. data/spec/factory_girl/disallows_duplicates_registry_spec.rb +0 -19
  96. data/spec/factory_girl/evaluator_class_definer_spec.rb +0 -77
  97. data/spec/factory_girl/factory_spec.rb +0 -259
  98. data/spec/factory_girl/find_definitions_spec.rb +0 -110
  99. data/spec/factory_girl/null_factory_spec.rb +0 -13
  100. data/spec/factory_girl/null_object_spec.rb +0 -22
  101. data/spec/factory_girl/registry_spec.rb +0 -68
  102. data/spec/factory_girl/sequence_spec.rb +0 -95
  103. data/spec/factory_girl/strategy/attributes_for_spec.rb +0 -18
  104. data/spec/factory_girl/strategy/build_spec.rb +0 -7
  105. data/spec/factory_girl/strategy/create_spec.rb +0 -25
  106. data/spec/factory_girl/strategy/stub_spec.rb +0 -38
  107. data/spec/factory_girl/strategy_calculator_spec.rb +0 -29
  108. data/spec/factory_girl_spec.rb +0 -22
  109. data/spec/spec_helper.rb +0 -26
  110. data/spec/support/macros/define_constant.rb +0 -86
  111. data/spec/support/matchers/callback.rb +0 -9
  112. data/spec/support/matchers/declaration.rb +0 -83
  113. data/spec/support/matchers/delegate.rb +0 -44
  114. data/spec/support/matchers/trait.rb +0 -11
  115. data/spec/support/shared_examples/strategy.rb +0 -90
@@ -1,91 +0,0 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- factory_girl (4.5.0)
5
- activesupport (>= 3.0.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.1.12)
11
- activesupport (= 3.1.12)
12
- builder (~> 3.0.0)
13
- i18n (~> 0.6)
14
- activerecord (3.1.12)
15
- activemodel (= 3.1.12)
16
- activesupport (= 3.1.12)
17
- arel (~> 2.2.3)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.1.12)
20
- multi_json (~> 1.0)
21
- appraisal (1.0.0)
22
- bundler
23
- rake
24
- thor (>= 0.14.0)
25
- arel (2.2.3)
26
- aruba (0.5.3)
27
- childprocess (>= 0.3.6)
28
- cucumber (>= 1.1.1)
29
- rspec-expectations (>= 2.7.0)
30
- bourne (1.5.0)
31
- mocha (>= 0.13.2, < 0.15)
32
- builder (3.0.4)
33
- childprocess (0.3.9)
34
- ffi (~> 1.0, >= 1.0.11)
35
- cucumber (1.3.15)
36
- builder (>= 2.1.2)
37
- diff-lcs (>= 1.1.3)
38
- gherkin (~> 2.12)
39
- multi_json (>= 1.7.5, < 2.0)
40
- multi_test (>= 0.1.1)
41
- diff-lcs (1.1.3)
42
- docile (1.1.3)
43
- ffi (1.9.3)
44
- ffi (1.9.3-java)
45
- gherkin (2.12.2)
46
- multi_json (~> 1.3)
47
- gherkin (2.12.2-java)
48
- multi_json (~> 1.3)
49
- i18n (0.6.9)
50
- metaclass (0.0.4)
51
- mocha (0.14.0)
52
- metaclass (~> 0.0.1)
53
- multi_json (1.10.1)
54
- multi_test (0.1.1)
55
- rake (10.3.2)
56
- rspec (2.12.0)
57
- rspec-core (~> 2.12.0)
58
- rspec-expectations (~> 2.12.0)
59
- rspec-mocks (~> 2.12.0)
60
- rspec-core (2.12.2)
61
- rspec-expectations (2.12.1)
62
- diff-lcs (~> 1.1.3)
63
- rspec-mocks (2.12.2)
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)
69
- sqlite3 (1.3.8)
70
- thor (0.19.1)
71
- timecop (0.7.1)
72
- tzinfo (0.3.39)
73
- yard (0.8.7.3)
74
-
75
- PLATFORMS
76
- java
77
- ruby
78
-
79
- DEPENDENCIES
80
- activerecord (~> 3.1.12)
81
- appraisal (~> 1.0.0)
82
- aruba
83
- bourne
84
- cucumber (~> 1.3.15)
85
- factory_girl!
86
- mocha (>= 0.12.8)
87
- rspec (~> 2.12.0)
88
- simplecov
89
- sqlite3
90
- timecop
91
- yard
@@ -1,62 +0,0 @@
1
- require "spec_helper"
2
-
3
- unless ActiveSupport::Notifications.respond_to?(:subscribed)
4
- module SubscribedBehavior
5
- def subscribed(callback, *args, &block)
6
- subscriber = subscribe(*args, &callback)
7
- yield
8
- ensure
9
- unsubscribe(subscriber)
10
- end
11
- end
12
-
13
- ActiveSupport::Notifications.extend SubscribedBehavior
14
- end
15
-
16
- describe "using ActiveSupport::Instrumentation to track factory interaction" do
17
- before do
18
- define_model("User", email: :string)
19
- FactoryGirl.define do
20
- factory :user do
21
- email "john@example.com"
22
-
23
- factory :slow_user do
24
- after(:build) { Kernel.sleep(0.1) }
25
- end
26
- end
27
-
28
- end
29
- end
30
-
31
- it "tracks proper time of creating the record" do
32
- time_to_execute = 0
33
- callback = ->(name, start, finish, id, payload) { time_to_execute = finish - start }
34
- ActiveSupport::Notifications.subscribed(callback, "factory_girl.run_factory") do
35
- FactoryGirl.build(:slow_user)
36
- end
37
-
38
- expect(time_to_execute).to be >= 0.1
39
- end
40
-
41
- it "builds the correct payload" do
42
- tracked_invocations = {}
43
-
44
- callback = ->(name, start, finish, id, payload) do
45
- factory_name = payload[:name]
46
- strategy_name = payload[:strategy]
47
- tracked_invocations[factory_name] ||= {}
48
- tracked_invocations[factory_name][strategy_name] ||= 0
49
- tracked_invocations[factory_name][strategy_name] += 1
50
- end
51
-
52
- ActiveSupport::Notifications.subscribed(callback, "factory_girl.run_factory") do
53
- FactoryGirl.build_list(:slow_user, 2)
54
- FactoryGirl.build_list(:user, 5)
55
- FactoryGirl.create_list(:user, 2)
56
- FactoryGirl.attributes_for(:slow_user)
57
- end
58
-
59
- expect(tracked_invocations[:slow_user]).to eq(build: 2, attributes_for: 1)
60
- expect(tracked_invocations[:user]).to eq(build: 5, create: 2)
61
- end
62
- end
@@ -1,19 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "aliases and overrides" do
4
- before do
5
- FactoryGirl.aliases << [/one/, "two"]
6
-
7
- define_model("User", two: :string, one: :string)
8
-
9
- FactoryGirl.define do
10
- factory :user do
11
- two "set value"
12
- end
13
- end
14
- end
15
-
16
- subject { FactoryGirl.create(:user, one: "override") }
17
- its(:one) { should eq "override" }
18
- its(:two) { should be_nil }
19
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "attribute aliases" do
4
- before do
5
- define_model('User', name: :string, age: :integer)
6
-
7
- define_model('Post', user_id: :integer) do
8
- belongs_to :user
9
- end
10
-
11
- FactoryGirl.define do
12
- factory :user do
13
- factory :user_with_name do
14
- name "John Doe"
15
- end
16
- end
17
-
18
- factory :post do
19
- user
20
- end
21
-
22
- factory :post_with_named_user, class: Post do
23
- user factory: :user_with_name, age: 20
24
- end
25
- end
26
- end
27
-
28
- context "assigning an association by foreign key" do
29
- subject { FactoryGirl.build(:post, user_id: 1) }
30
-
31
- it "doesn't assign both an association and its foreign key" do
32
- expect(subject.user_id).to eq 1
33
- end
34
- end
35
-
36
- context "assigning an association by passing factory" do
37
- subject { FactoryGirl.create(:post_with_named_user).user }
38
-
39
- it "assigns attributes correctly" do
40
- expect(subject.name).to eq "John Doe"
41
- expect(subject.age).to eq 20
42
- end
43
- end
44
- end
45
-
@@ -1,68 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "declaring attributes on a Factory that are private methods on Object" do
4
- before do
5
- define_model("Website", system: :boolean, link: :string, sleep: :integer)
6
-
7
- FactoryGirl.define do
8
- factory :website do
9
- system false
10
- link "http://example.com"
11
- sleep 15
12
- end
13
- end
14
- end
15
-
16
- subject { FactoryGirl.build(:website, sleep: -5) }
17
-
18
- its(:system) { should eq false }
19
- its(:link) { should eq "http://example.com" }
20
- its(:sleep) { should eq -5 }
21
- end
22
-
23
- describe "assigning overrides that are also private methods on object" do
24
- before do
25
- define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string)
26
-
27
- Object.class_eval do
28
- private
29
- def some_funky_method(args)
30
- end
31
- end
32
-
33
- FactoryGirl.define do
34
- factory :website do
35
- more_format { "format: #{format}" }
36
- end
37
- end
38
- end
39
-
40
- after do
41
- Object.send(:undef_method, :some_funky_method)
42
- end
43
-
44
- subject { FactoryGirl.build(:website, format: "Great", y: 12345, some_funky_method: "foobar!") }
45
- its(:format) { should eq "Great" }
46
- its(:y) { should eq 12345 }
47
- its(:more_format) { should eq "format: Great" }
48
- its(:some_funky_method) { should eq "foobar!" }
49
- end
50
-
51
- describe "accessing methods from the instance within a dynamic attribute that is also a private method on object" do
52
- before do
53
- define_model("Website", more_format: :string) do
54
- def format
55
- "This is an awesome format"
56
- end
57
- end
58
-
59
- FactoryGirl.define do
60
- factory :website do
61
- more_format { "format: #{format}" }
62
- end
63
- end
64
- end
65
-
66
- subject { FactoryGirl.build(:website) }
67
- its(:more_format) { should eq "format: This is an awesome format" }
68
- end
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "a generated attributes hash" do
4
- include FactoryGirl::Syntax::Methods
5
-
6
- before do
7
- define_model('User')
8
- define_model('Comment')
9
-
10
- define_model('Post', title: :string,
11
- body: :string,
12
- summary: :string,
13
- user_id: :integer) do
14
- belongs_to :user
15
- has_many :comments
16
- end
17
-
18
- FactoryGirl.define do
19
- factory :user
20
- factory :comment
21
-
22
- factory :post do
23
- title { "default title" }
24
- body { "default body" }
25
- summary { title }
26
- user
27
- comments do |c|
28
- [c.association(:comment)]
29
- end
30
- end
31
- end
32
- end
33
-
34
- subject { attributes_for(:post, title: 'overridden title') }
35
-
36
- it "assigns an overridden value" do
37
- expect(subject[:title]).to eq "overridden title"
38
- end
39
-
40
- it "assigns a default value" do
41
- expect(subject[:body]).to eq "default body"
42
- end
43
-
44
- it "assigns a lazy, dependent attribute" do
45
- expect(subject[:summary]).to eq "overridden title"
46
- end
47
-
48
- it "doesn't assign associations" do
49
- expect(subject).not_to have_key(:user_id)
50
- expect(subject).not_to have_key(:user)
51
- end
52
- end
53
-
54
- describe "calling `attributes_for` with a block" do
55
- include FactoryGirl::Syntax::Methods
56
-
57
- before do
58
- define_model('Company', name: :string)
59
-
60
- FactoryGirl.define do
61
- factory :company
62
- end
63
- end
64
-
65
- it "passes the hash of attributes" do
66
- attributes_for(:company, name: 'thoughtbot') do |attributes|
67
- expect(attributes[:name]).to eq('thoughtbot')
68
- end
69
- end
70
-
71
- it "returns the hash of attributes" do
72
- expected = nil
73
-
74
- result = attributes_for(:company) do |attributes|
75
- expected = attributes
76
- "hello!"
77
- end
78
- expect(result).to eq expected
79
- end
80
- end
81
-
82
- describe "`attributes_for` for a class whose constructor has required params" do
83
- before do
84
- define_model("User", name: :string) do
85
- def initialize(arg1, arg2); end
86
- end
87
-
88
- FactoryGirl.define do
89
- factory :user do
90
- name "John Doe"
91
- end
92
- end
93
- end
94
-
95
- subject { FactoryGirl.attributes_for(:user) }
96
- its([:name]) { should eq "John Doe" }
97
- end
@@ -1,53 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "calling methods on the model instance" do
4
- before do
5
- define_model('User', age: :integer, age_copy: :integer) do
6
- def age
7
- read_attribute(:age) || 18
8
- end
9
- end
10
-
11
- FactoryGirl.define do
12
- factory :user do
13
- age_copy { age }
14
- end
15
- end
16
- end
17
-
18
- context "without the attribute being overridden" do
19
- it "returns the correct value from the instance" do
20
- expect(FactoryGirl.build(:user).age_copy).to eq 18
21
- end
22
-
23
- it "returns nil during attributes_for" do
24
- expect(FactoryGirl.attributes_for(:user)[:age_copy]).to be_nil
25
- end
26
-
27
- it "doesn't instantiate a record with attributes_for" do
28
- User.stubs(:new)
29
- FactoryGirl.attributes_for(:user)
30
- expect(User).to have_received(:new).never
31
- end
32
- end
33
-
34
- context "with the attribute being overridden" do
35
- it "uses the overridden value" do
36
- expect(FactoryGirl.build(:user, age_copy: nil).age_copy).to be_nil
37
- end
38
-
39
- it "uses the overridden value during attributes_for" do
40
- expect(FactoryGirl.attributes_for(:user, age_copy: 25)[:age_copy]).to eq 25
41
- end
42
- end
43
-
44
- context "with the referenced attribute being overridden" do
45
- it "uses the overridden value" do
46
- expect(FactoryGirl.build(:user, age: nil).age_copy).to be_nil
47
- end
48
-
49
- it "uses the overridden value during attributes_for" do
50
- expect(FactoryGirl.attributes_for(:user, age: 25)[:age_copy]).to eq 25
51
- end
52
- end
53
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "a generated attributes hash where order matters" do
4
- include FactoryGirl::Syntax::Methods
5
-
6
- before do
7
- define_model('ParentModel', static: :integer,
8
- evaluates_first: :integer,
9
- evaluates_second: :integer,
10
- evaluates_third: :integer)
11
-
12
- FactoryGirl.define do
13
- factory :parent_model do
14
- evaluates_first { static }
15
- evaluates_second { evaluates_first }
16
- evaluates_third { evaluates_second }
17
-
18
- factory :child_model do
19
- static 1
20
- end
21
- end
22
-
23
- factory :without_parent, class: ParentModel do
24
- evaluates_first { static }
25
- evaluates_second { evaluates_first }
26
- evaluates_third { evaluates_second }
27
- static 1
28
- end
29
- end
30
- end
31
-
32
- context "factory with a parent" do
33
- subject { FactoryGirl.build(:child_model) }
34
-
35
- it "assigns attributes in the order they're defined with preference to static attributes" do
36
- expect(subject[:evaluates_first]).to eq 1
37
- expect(subject[:evaluates_second]).to eq 1
38
- expect(subject[:evaluates_third]).to eq 1
39
- end
40
- end
41
-
42
- context "factory without a parent" do
43
- subject { FactoryGirl.build(:without_parent) }
44
-
45
- it "assigns attributes in the order they're defined with preference to static attributes without a parent class" do
46
- expect(subject[:evaluates_first]).to eq 1
47
- expect(subject[:evaluates_second]).to eq 1
48
- expect(subject[:evaluates_third]).to eq 1
49
- end
50
- end
51
- end