factory_girl 2.6.4 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.travis.yml +0 -3
  2. data/Appraisals +0 -4
  3. data/Changelog +0 -4
  4. data/Gemfile.lock +7 -4
  5. data/Rakefile +0 -12
  6. data/factory_girl.gemspec +3 -3
  7. data/features/support/env.rb +3 -0
  8. data/gemfiles/3.0.gemfile.lock +8 -4
  9. data/gemfiles/3.1.gemfile.lock +7 -4
  10. data/gemfiles/3.2.gemfile.lock +7 -4
  11. data/lib/factory_girl.rb +0 -1
  12. data/lib/factory_girl/attribute_assigner.rb +2 -2
  13. data/lib/factory_girl/declaration.rb +0 -5
  14. data/lib/factory_girl/definition.rb +1 -1
  15. data/lib/factory_girl/definition_proxy.rb +1 -1
  16. data/lib/factory_girl/errors.rb +1 -1
  17. data/lib/factory_girl/evaluator.rb +2 -5
  18. data/lib/factory_girl/factory.rb +4 -20
  19. data/lib/factory_girl/null_factory.rb +1 -2
  20. data/lib/factory_girl/null_object.rb +3 -15
  21. data/lib/factory_girl/sequence.rb +0 -4
  22. data/lib/factory_girl/step_definitions.rb +1 -1
  23. data/lib/factory_girl/syntax/blueprint.rb +2 -2
  24. data/lib/factory_girl/syntax/default.rb +1 -1
  25. data/lib/factory_girl/syntax/generate.rb +1 -1
  26. data/lib/factory_girl/syntax/make.rb +1 -1
  27. data/lib/factory_girl/syntax/vintage.rb +13 -32
  28. data/lib/factory_girl/trait.rb +1 -1
  29. data/lib/factory_girl/version.rb +1 -1
  30. data/spec/acceptance/aliases_spec.rb +3 -3
  31. data/spec/acceptance/attribute_aliases_spec.rb +5 -5
  32. data/spec/acceptance/attribute_existing_on_object_spec.rb +5 -5
  33. data/spec/acceptance/attributes_for_spec.rb +8 -8
  34. data/spec/acceptance/attributes_from_instance_spec.rb +5 -5
  35. data/spec/acceptance/attributes_ordered_spec.rb +5 -5
  36. data/spec/acceptance/build_list_spec.rb +2 -2
  37. data/spec/acceptance/build_spec.rb +6 -6
  38. data/spec/acceptance/build_stubbed_spec.rb +7 -7
  39. data/spec/acceptance/callbacks_spec.rb +3 -3
  40. data/spec/acceptance/create_list_spec.rb +6 -6
  41. data/spec/acceptance/create_spec.rb +13 -42
  42. data/spec/acceptance/define_child_before_parent_spec.rb +2 -2
  43. data/spec/acceptance/definition_spec.rb +2 -2
  44. data/spec/acceptance/initialize_with_spec.rb +7 -7
  45. data/spec/acceptance/modify_factories_spec.rb +5 -5
  46. data/spec/acceptance/modify_inherited_spec.rb +8 -8
  47. data/spec/acceptance/overrides_spec.rb +4 -4
  48. data/spec/acceptance/parent_spec.rb +3 -3
  49. data/spec/acceptance/stub_spec.rb +12 -41
  50. data/spec/acceptance/syntax/blueprint_spec.rb +6 -3
  51. data/spec/acceptance/syntax/generate_spec.rb +4 -4
  52. data/spec/acceptance/syntax/make_spec.rb +3 -3
  53. data/spec/acceptance/syntax/sham_spec.rb +5 -5
  54. data/spec/acceptance/syntax/vintage_spec.rb +28 -46
  55. data/spec/acceptance/traits_spec.rb +33 -33
  56. data/spec/acceptance/transient_attributes_spec.rb +7 -59
  57. data/spec/factory_girl/aliases_spec.rb +1 -1
  58. data/spec/factory_girl/attribute/association_spec.rb +2 -2
  59. data/spec/factory_girl/attribute/dynamic_spec.rb +2 -2
  60. data/spec/factory_girl/declaration_list_spec.rb +7 -7
  61. data/spec/factory_girl/definition_proxy_spec.rb +6 -6
  62. data/spec/factory_girl/definition_spec.rb +3 -3
  63. data/spec/factory_girl/evaluator_class_definer_spec.rb +5 -5
  64. data/spec/factory_girl/factory_spec.rb +19 -69
  65. data/spec/factory_girl/null_factory_spec.rb +4 -5
  66. data/spec/factory_girl/registry_spec.rb +1 -1
  67. data/spec/factory_girl/sequence_spec.rb +3 -4
  68. data/spec/factory_girl/strategy/attributes_for_spec.rb +2 -2
  69. data/spec/factory_girl/strategy/build_spec.rb +1 -1
  70. data/spec/factory_girl/strategy/create_spec.rb +1 -1
  71. data/spec/factory_girl/strategy/stub_spec.rb +2 -2
  72. data/spec/spec_helper.rb +3 -0
  73. data/spec/support/macros/define_constant.rb +2 -2
  74. data/spec/support/shared_examples/strategy.rb +12 -22
  75. metadata +32 -41
  76. data/gemfiles/2.3.gemfile.lock +0 -72
  77. data/lib/factory_girl/deprecated.rb +0 -18
  78. data/spec/acceptance/default_strategy_spec.rb +0 -24
  79. data/spec/acceptance/nested_attributes_spec.rb +0 -32
  80. data/spec/factory_girl/deprecated_spec.rb +0 -45
@@ -6,10 +6,10 @@ describe "a generated stub instance" do
6
6
  before do
7
7
  define_model('User')
8
8
 
9
- define_model('Post', :title => :string,
10
- :body => :string,
11
- :age => :integer,
12
- :user_id => :integer) do
9
+ define_model('Post', title: :string,
10
+ body: :string,
11
+ age: :integer,
12
+ user_id: :integer) do
13
13
  belongs_to :user
14
14
  end
15
15
 
@@ -24,7 +24,7 @@ describe "a generated stub instance" do
24
24
  end
25
25
  end
26
26
 
27
- subject { build_stubbed(:post, :title => 'overridden title') }
27
+ subject { build_stubbed(:post, title: 'overridden title') }
28
28
 
29
29
  it "assigns a default attribute" do
30
30
  subject.body.should == 'default body'
@@ -80,7 +80,7 @@ describe "calling `build_stubbed` with a block" do
80
80
  include FactoryGirl::Syntax::Methods
81
81
 
82
82
  before do
83
- define_model('Company', :name => :string)
83
+ define_model('Company', name: :string)
84
84
 
85
85
  FactoryGirl.define do
86
86
  factory :company
@@ -88,7 +88,7 @@ describe "calling `build_stubbed` with a block" do
88
88
  end
89
89
 
90
90
  it "passes the stub instance" do
91
- build_stubbed(:company, :name => 'thoughtbot') do |company|
91
+ build_stubbed(:company, name: 'thoughtbot') do |company|
92
92
  company.name.should eq('thoughtbot')
93
93
  expect { company.save }.to raise_error(RuntimeError)
94
94
  end
@@ -2,16 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe "callbacks" do
4
4
  before do
5
- define_model("User", :first_name => :string, :last_name => :string)
5
+ define_model("User", first_name: :string, last_name: :string)
6
6
 
7
7
  FactoryGirl.define do
8
- factory :user_with_callbacks, :class => :user do
8
+ factory :user_with_callbacks, class: :user do
9
9
  after_stub { |user| user.first_name = 'Stubby' }
10
10
  after_build { |user| user.first_name = 'Buildy' }
11
11
  after_create { |user| user.last_name = 'Createy' }
12
12
  end
13
13
 
14
- factory :user_with_inherited_callbacks, :parent => :user_with_callbacks do
14
+ factory :user_with_inherited_callbacks, parent: :user_with_callbacks do
15
15
  after_stub { |user| user.last_name = 'Double-Stubby' }
16
16
  after_build { |user| user.first_name = 'Child-Buildy' }
17
17
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "create multiple instances" do
4
4
  before do
5
- define_model('Post', :title => :string)
5
+ define_model('Post', title: :string)
6
6
 
7
7
  FactoryGirl.define do
8
8
  factory(:post) do |post|
@@ -30,7 +30,7 @@ describe "create multiple instances" do
30
30
  end
31
31
 
32
32
  context "with default attributes" do
33
- subject { FactoryGirl.create_list(:post, 20, :title => "The Hunting of the Snark") }
33
+ subject { FactoryGirl.create_list(:post, 20, title: "The Hunting of the Snark") }
34
34
 
35
35
  it "overrides the default values" do
36
36
  subject.each do |record|
@@ -42,11 +42,11 @@ end
42
42
 
43
43
  describe "multiple creates and ignored attributes to dynamically build attribute lists" do
44
44
  before do
45
- define_model('User', :name => :string) do
45
+ define_model('User', name: :string) do
46
46
  has_many :posts
47
47
  end
48
48
 
49
- define_model('Post', :title => :string, :user_id => :integer) do
49
+ define_model('Post', title: :string, user_id: :integer) do
50
50
  belongs_to :user
51
51
  end
52
52
 
@@ -65,7 +65,7 @@ describe "multiple creates and ignored attributes to dynamically build attribute
65
65
  end
66
66
 
67
67
  after_create do |user, evaluator|
68
- FactoryGirl.create_list(:post, evaluator.posts_count, :user => user)
68
+ FactoryGirl.create_list(:post, evaluator.posts_count, user: user)
69
69
  end
70
70
  end
71
71
  end
@@ -77,6 +77,6 @@ describe "multiple creates and ignored attributes to dynamically build attribute
77
77
  end
78
78
 
79
79
  it "allows the number of posts to be modified" do
80
- FactoryGirl.create(:user_with_posts, :posts_count => 2).posts.length.should == 2
80
+ FactoryGirl.create(:user_with_posts, posts_count: 2).posts.length.should == 2
81
81
  end
82
82
  end
@@ -6,7 +6,7 @@ describe "a created instance" do
6
6
  before do
7
7
  define_model('User')
8
8
 
9
- define_model('Post', :user_id => :integer) do
9
+ define_model('Post', user_id: :integer) do
10
10
  belongs_to :user
11
11
  end
12
12
 
@@ -31,59 +31,30 @@ describe "a created instance" do
31
31
  end
32
32
  end
33
33
 
34
- describe "a created instance, specifying :strategy => build" do
34
+ describe "a created instance, specifying strategy: :build" do
35
35
  include FactoryGirl::Syntax::Methods
36
36
 
37
- def define_factories_with_method
38
- FactoryGirl.define do
39
- factory :user
37
+ before do
38
+ define_model('User')
40
39
 
41
- factory :post do
42
- association(:user, :method => :build)
43
- end
40
+ define_model('Post', user_id: :integer) do
41
+ belongs_to :user
44
42
  end
45
- end
46
43
 
47
- def define_factories_with_strategy
48
44
  FactoryGirl.define do
49
45
  factory :user
50
46
 
51
47
  factory :post do
52
- association(:user, :strategy => :build)
48
+ association(:user, strategy: :build)
53
49
  end
54
50
  end
55
51
  end
56
52
 
57
- before do
58
- define_model('User')
59
-
60
- define_model('Post', :user_id => :integer) do
61
- belongs_to :user
62
- end
63
- end
64
-
65
- context "associations declared with :strategy" do
66
- before { define_factories_with_strategy }
67
- subject { build_stubbed(:post) }
68
-
69
- subject { create('post') }
70
-
71
- it "still saves associations (:strategy => :build only affects build, not create)" do
72
- subject.user.should be_kind_of(User)
73
- subject.user.should_not be_new_record
74
- end
75
- end
76
-
77
- context "associations declared with :method" do
78
- before { define_factories_with_method }
79
- subject { build_stubbed(:post) }
80
-
81
- subject { create('post') }
53
+ subject { create(:post) }
82
54
 
83
- it "still saves associations (:method => :build only affects build, not create)" do
84
- subject.user.should be_kind_of(User)
85
- subject.user.should_not be_new_record
86
- end
55
+ it "saves associations (strategy: :build only affects build, not create)" do
56
+ subject.user.should be_kind_of(User)
57
+ subject.user.should_not be_new_record
87
58
  end
88
59
  end
89
60
 
@@ -123,7 +94,7 @@ describe "calling `create` with a block" do
123
94
  include FactoryGirl::Syntax::Methods
124
95
 
125
96
  before do
126
- define_model('Company', :name => :string)
97
+ define_model('Company', name: :string)
127
98
 
128
99
  FactoryGirl.define do
129
100
  factory :company
@@ -131,7 +102,7 @@ describe "calling `create` with a block" do
131
102
  end
132
103
 
133
104
  it "passes the created instance" do
134
- create(:company, :name => 'thoughtbot') do |company|
105
+ create(:company, name: 'thoughtbot') do |company|
135
106
  company.name.should eq('thoughtbot')
136
107
  end
137
108
  end
@@ -2,10 +2,10 @@ require "spec_helper"
2
2
 
3
3
  describe "defining a child factory before a parent" do
4
4
  before do
5
- define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string, :login => :string)
5
+ define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
6
6
 
7
7
  FactoryGirl.define do
8
- factory :admin, :parent => :user do
8
+ factory :admin, parent: :user do
9
9
  admin true
10
10
  end
11
11
 
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe "an instance generated by a factory with a custom class name" do
4
4
  before do
5
- define_model("User", :admin => :boolean)
5
+ define_model("User", admin: :boolean)
6
6
 
7
7
  FactoryGirl.define do
8
8
  factory :user
9
9
 
10
- factory :admin, :class => User do
10
+ factory :admin, class: User do
11
11
  admin { true }
12
12
  end
13
13
  end
@@ -4,9 +4,9 @@ describe "initialize_with with non-FG attributes" do
4
4
  include FactoryGirl::Syntax::Methods
5
5
 
6
6
  before do
7
- define_model("User", :name => :string, :age => :integer) do
7
+ define_model("User", name: :string, age: :integer) do
8
8
  def self.construct(name, age)
9
- new(:name => name, :age => age)
9
+ new(name: name, age: age)
10
10
  end
11
11
  end
12
12
 
@@ -26,9 +26,9 @@ describe "initialize_with with FG attributes that are ignored" do
26
26
  include FactoryGirl::Syntax::Methods
27
27
 
28
28
  before do
29
- define_model("User", :name => :string) do
29
+ define_model("User", name: :string) do
30
30
  def self.construct(name)
31
- new(:name => "#{name} from .construct")
31
+ new(name: "#{name} from .construct")
32
32
  end
33
33
  end
34
34
 
@@ -51,9 +51,9 @@ describe "initialize_with with FG attributes that are not ignored" do
51
51
  include FactoryGirl::Syntax::Methods
52
52
 
53
53
  before do
54
- define_model("User", :name => :string) do
54
+ define_model("User", name: :string) do
55
55
  def self.construct(name)
56
- new(:name => "#{name} from .construct")
56
+ new(name: "#{name} from .construct")
57
57
  end
58
58
  end
59
59
 
@@ -98,7 +98,7 @@ describe "initialize_with non-ORM-backed objects" do
98
98
  end
99
99
 
100
100
  it "allows for overrides" do
101
- build(:report_generator, :name => "Overridden").name.should == "Overridden"
101
+ build(:report_generator, name: "Overridden").name.should == "Overridden"
102
102
  end
103
103
 
104
104
  it "generates random data" do
@@ -4,7 +4,7 @@ describe "modifying factories" do
4
4
  include FactoryGirl::Syntax::Methods
5
5
 
6
6
  before do
7
- define_model('User', :name => :string, :admin => :boolean, :email => :string, :login => :string)
7
+ define_model('User', name: :string, admin: :boolean, email: :string, login: :string)
8
8
 
9
9
  FactoryGirl.define do
10
10
  sequence(:email) {|n| "user#{n}@example.com" }
@@ -114,14 +114,14 @@ describe "modifying factories" do
114
114
  end
115
115
 
116
116
  context "overriding dynamic attributes" do
117
- subject { create(:user, :email => "perfect@example.com") }
117
+ subject { create(:user, email: "perfect@example.com") }
118
118
 
119
119
  its(:name) { should == "Great User" }
120
120
  its(:email) { should == "perfect@example.com" }
121
121
  end
122
122
 
123
123
  context "overriding static attributes" do
124
- subject { create(:user, :name => "wonderful") }
124
+ subject { create(:user, name: "wonderful") }
125
125
 
126
126
  its(:name) { should == "wonderful" }
127
127
  its(:email) { should == "wonderful-modified@example.com" }
@@ -138,7 +138,7 @@ describe "modifying factories" do
138
138
  end
139
139
 
140
140
  context "overriding dynamic attributes" do
141
- subject { create(:admin, :email => "perfect@example.com") }
141
+ subject { create(:admin, email: "perfect@example.com") }
142
142
 
143
143
  its(:name) { should == "Great User" }
144
144
  its(:email) { should == "perfect@example.com" }
@@ -146,7 +146,7 @@ describe "modifying factories" do
146
146
  end
147
147
 
148
148
  context "overriding static attributes" do
149
- subject { create(:admin, :name => "wonderful") }
149
+ subject { create(:admin, name: "wonderful") }
150
150
 
151
151
  its(:name) { should == "wonderful" }
152
152
  its(:email) { should == "wonderful-modified@example.com" }
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe "modifying inherited factories with traits" do
4
4
  before do
5
- define_model('User', :gender => :string, :admin => :boolean, :age => :integer)
5
+ define_model('User', gender: :string, admin: :boolean, age: :integer)
6
6
  FactoryGirl.define do
7
7
  factory :user do
8
8
  trait(:female) { gender "Female" }
@@ -29,13 +29,13 @@ describe "modifying inherited factories with traits" do
29
29
  end
30
30
 
31
31
  it "returns the correct value for overridden attributes from traits" do
32
- Factory.build(:male_user).gender.should == "Male"
32
+ FactoryGirl.build(:male_user).gender.should == "Male"
33
33
  end
34
34
 
35
35
  it "returns the correct value for overridden attributes from traits defining multiple attributes" do
36
- Factory.build(:female_user).gender.should == "Female"
37
- Factory.build(:female_user).age.should == 25
38
- Factory.build(:female_user).admin.should == true
36
+ FactoryGirl.build(:female_user).gender.should == "Female"
37
+ FactoryGirl.build(:female_user).age.should == 25
38
+ FactoryGirl.build(:female_user).admin.should == true
39
39
  end
40
40
 
41
41
  it "allows modification of attributes created via traits" do
@@ -45,8 +45,8 @@ describe "modifying inherited factories with traits" do
45
45
  end
46
46
  end
47
47
 
48
- Factory.build(:male_user).gender.should == "Male"
49
- Factory.build(:male_user).age.should == 20
50
- Factory.build(:male_user).admin.should == true
48
+ FactoryGirl.build(:male_user).gender.should == "Male"
49
+ FactoryGirl.build(:male_user).age.should == 20
50
+ FactoryGirl.build(:male_user).admin.should == true
51
51
  end
52
52
  end
@@ -3,10 +3,10 @@ require 'active_support/ordered_hash'
3
3
 
4
4
  describe "attribute overrides" do
5
5
  before do
6
- define_model('User', :admin => :boolean)
7
- define_model('Post', :title => :string,
8
- :secure => :boolean,
9
- :user_id => :integer) do
6
+ define_model('User', admin: :boolean)
7
+ define_model('Post', title: :string,
8
+ secure: :boolean,
9
+ user_id: :integer) do
10
10
  belongs_to :user
11
11
 
12
12
  def secure=(value)
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "an instance generated by a factory that inherits from another factory" do
4
4
  before do
5
- define_model("User", :name => :string, :admin => :boolean, :email => :string, :upper_email => :string, :login => :string)
5
+ define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
6
6
 
7
7
  FactoryGirl.define do
8
8
  factory :user do
@@ -67,7 +67,7 @@ end
67
67
 
68
68
  describe "nested factories with different parents" do
69
69
  before do
70
- define_model("User", :name => :string)
70
+ define_model("User", name: :string)
71
71
 
72
72
  FactoryGirl.define do
73
73
  factory :user do
@@ -77,7 +77,7 @@ describe "nested factories with different parents" do
77
77
  name "John Doe"
78
78
  end
79
79
 
80
- factory :uppercase_male_user, :parent => :male_user do
80
+ factory :uppercase_male_user, parent: :male_user do
81
81
  after_build {|user| user.name = user.name.upcase }
82
82
  end
83
83
  end
@@ -6,7 +6,7 @@ describe "a stubbed instance" do
6
6
  before do
7
7
  define_model('User')
8
8
 
9
- define_model('Post', :user_id => :integer) do
9
+ define_model('Post', user_id: :integer) do
10
10
  belongs_to :user
11
11
  end
12
12
 
@@ -34,58 +34,29 @@ end
34
34
  describe "a stubbed instance overriding strategy" do
35
35
  include FactoryGirl::Syntax::Methods
36
36
 
37
- def define_factories_with_method
38
- FactoryGirl.define do
39
- factory :user
40
-
41
- factory :post do
42
- association(:user, :method => :build)
43
- end
37
+ before do
38
+ define_model('User')
39
+ define_model('Post', user_id: :integer) do
40
+ belongs_to :user
44
41
  end
45
- end
46
42
 
47
- def define_factories_with_strategy
48
43
  FactoryGirl.define do
49
44
  factory :user
50
45
 
51
46
  factory :post do
52
- association(:user, :strategy => :build)
47
+ association(:user, strategy: :build)
53
48
  end
54
49
  end
55
50
  end
56
51
 
57
- before do
58
- define_model('User')
59
- define_model('Post', :user_id => :integer) do
60
- belongs_to :user
61
- end
62
- end
63
-
64
- context "associations declared with :strategy" do
65
- before { define_factories_with_strategy }
66
- subject { build_stubbed(:post) }
67
-
68
- it "acts as if it is saved in the database" do
69
- should_not be_new_record
70
- end
52
+ subject { build_stubbed(:post) }
71
53
 
72
- it "assigns associations and acts as if it is saved" do
73
- subject.user.should be_kind_of(User)
74
- subject.user.should_not be_new_record
75
- end
54
+ it "acts as if it is saved in the database" do
55
+ should_not be_new_record
76
56
  end
77
57
 
78
- context "associations declared with :method" do
79
- before { define_factories_with_method }
80
- subject { build_stubbed(:post) }
81
-
82
- it "acts as if it is saved in the database" do
83
- should_not be_new_record
84
- end
85
-
86
- it "assigns associations and acts as if it is saved" do
87
- subject.user.should be_kind_of(User)
88
- subject.user.should_not be_new_record
89
- end
58
+ it "assigns associations and acts as if it is saved" do
59
+ subject.user.should be_kind_of(User)
60
+ subject.user.should_not be_new_record
90
61
  end
91
62
  end