factory_girl 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/Changelog +25 -0
  2. data/GETTING_STARTED.md +10 -3
  3. data/Gemfile.lock +1 -1
  4. data/README.md +1 -1
  5. data/gemfiles/2.1.gemfile.lock +1 -1
  6. data/gemfiles/2.3.gemfile.lock +1 -1
  7. data/gemfiles/3.0.gemfile.lock +1 -1
  8. data/gemfiles/3.1.gemfile.lock +1 -1
  9. data/lib/factory_girl.rb +9 -0
  10. data/lib/factory_girl/attribute.rb +2 -6
  11. data/lib/factory_girl/attribute/association.rb +1 -1
  12. data/lib/factory_girl/attribute/dynamic.rb +8 -3
  13. data/lib/factory_girl/attribute/sequence.rb +8 -3
  14. data/lib/factory_girl/attribute/static.rb +7 -3
  15. data/lib/factory_girl/attribute_list.rb +5 -4
  16. data/lib/factory_girl/declaration.rb +5 -5
  17. data/lib/factory_girl/declaration/association.rb +1 -1
  18. data/lib/factory_girl/declaration/dynamic.rb +3 -3
  19. data/lib/factory_girl/declaration/implicit.rb +3 -3
  20. data/lib/factory_girl/declaration/static.rb +3 -3
  21. data/lib/factory_girl/definition_proxy.rb +14 -11
  22. data/lib/factory_girl/factory.rb +71 -79
  23. data/lib/factory_girl/proxy.rb +6 -1
  24. data/lib/factory_girl/proxy/attributes_for.rb +2 -6
  25. data/lib/factory_girl/proxy/build.rb +2 -7
  26. data/lib/factory_girl/proxy/stub.rb +2 -6
  27. data/lib/factory_girl/step_definitions.rb +3 -2
  28. data/lib/factory_girl/syntax/default.rb +1 -9
  29. data/lib/factory_girl/syntax/methods.rb +16 -8
  30. data/lib/factory_girl/syntax/vintage.rb +0 -3
  31. data/lib/factory_girl/version.rb +1 -1
  32. data/spec/acceptance/attribute_existing_on_object.rb +21 -0
  33. data/spec/acceptance/attributes_for_spec.rb +17 -0
  34. data/spec/acceptance/build_spec.rb +17 -0
  35. data/spec/acceptance/build_stubbed_spec.rb +18 -0
  36. data/spec/acceptance/create_spec.rb +18 -0
  37. data/spec/acceptance/define_child_before_parent_spec.rb +21 -0
  38. data/spec/acceptance/syntax/blueprint_spec.rb +2 -2
  39. data/spec/acceptance/syntax/generate_spec.rb +9 -9
  40. data/spec/acceptance/syntax/make_spec.rb +6 -6
  41. data/spec/acceptance/syntax/sham_spec.rb +3 -3
  42. data/spec/acceptance/syntax/vintage_spec.rb +30 -29
  43. data/spec/acceptance/transient_attributes_spec.rb +45 -3
  44. data/spec/factory_girl/attribute/dynamic_spec.rb +5 -5
  45. data/spec/factory_girl/attribute/sequence_spec.rb +1 -1
  46. data/spec/factory_girl/attribute/static_spec.rb +3 -3
  47. data/spec/factory_girl/attribute_list_spec.rb +9 -24
  48. data/spec/factory_girl/attribute_spec.rb +3 -3
  49. data/spec/factory_girl/definition_proxy_spec.rb +23 -42
  50. data/spec/factory_girl/factory_spec.rb +26 -95
  51. data/spec/factory_girl/find_definitions_spec.rb +1 -1
  52. data/spec/support/shared_examples/proxy.rb +1 -1
  53. metadata +119 -122
@@ -29,28 +29,29 @@ describe "vintage syntax" do
29
29
  end
30
30
  end
31
31
 
32
- it "should raise an ArgumentError when trying to use a non-existent strategy" do
33
- lambda {
32
+ it "raises an ArgumentError when trying to use a non-existent strategy" do
33
+ expect {
34
34
  Factory.define(:object, :default_strategy => :nonexistent) {}
35
- }.should raise_error(ArgumentError)
35
+ }.to raise_error(ArgumentError)
36
36
  end
37
37
 
38
- it "should raise Factory::SequenceAbuseError" do
38
+ it "raises Factory::SequenceAbuseError" do
39
39
  Factory.define :sequence_abuser, :class => User do |factory|
40
40
  factory.first_name { Factory.sequence(:name) }
41
41
  end
42
42
 
43
- lambda {
43
+ expect {
44
44
  Factory(:sequence_abuser)
45
- }.should raise_error(FactoryGirl::SequenceAbuseError)
45
+ }.to raise_error(FactoryGirl::SequenceAbuseError)
46
46
  end
47
47
  end
48
48
 
49
49
  describe Factory, "referencing a nonexistent factory as a parent" do
50
- it "should raise an ArgumentError when trying to use a non-existent factory as parent" do
51
- lambda {
50
+ it "raises an ArgumentError when trying to use a non-existent factory as parent" do
51
+ expect {
52
52
  Factory.define(:child, :parent => :nonexsitent) {}
53
- }.should raise_error(ArgumentError)
53
+ Factory.build(:child)
54
+ }.to raise_error(ArgumentError)
54
55
  end
55
56
  end
56
57
 
@@ -64,13 +65,13 @@ describe "defining a factory" do
64
65
  FactoryGirl::DefinitionProxy.stubs(:new => @proxy)
65
66
  end
66
67
 
67
- it "should create a new factory using the specified name and options" do
68
+ it "creates a new factory using the specified name and options" do
68
69
  FactoryGirl::Factory.stubs(:new => @factory)
69
70
  Factory.define(@name, @options) {|f| }
70
71
  FactoryGirl::Factory.should have_received(:new).with(@name, @options)
71
72
  end
72
73
 
73
- it "should pass the factory do the block" do
74
+ it "passes the factory do the block" do
74
75
  yielded = nil
75
76
  Factory.define(@name) do |y|
76
77
  yielded = y
@@ -78,7 +79,7 @@ describe "defining a factory" do
78
79
  yielded.should == @proxy
79
80
  end
80
81
 
81
- it "should add the factory to the list of factories" do
82
+ it "adds the factory to the list of factories" do
82
83
  Factory.define(@name) {|f| }
83
84
  @factory.should == FactoryGirl.factory_by_name(@name)
84
85
  end
@@ -92,48 +93,48 @@ describe "after defining a factory" do
92
93
  FactoryGirl.register_factory(@factory)
93
94
  end
94
95
 
95
- it "should use Proxy::AttributesFor for Factory.attributes_for" do
96
+ it "uses Proxy::AttributesFor for Factory.attributes_for" do
96
97
  @factory.stubs(:run => "result")
97
98
  Factory.attributes_for(@name, :attr => 'value').should == 'result'
98
99
  @factory.should have_received(:run).with(FactoryGirl::Proxy::AttributesFor, :attr => 'value')
99
100
  end
100
101
 
101
- it "should use Proxy::Build for Factory.build" do
102
+ it "uses Proxy::Build for Factory.build" do
102
103
  @factory.stubs(:run => "result")
103
104
  Factory.build(@name, :attr => 'value').should == 'result'
104
105
  @factory.should have_received(:run).with(FactoryGirl::Proxy::Build, :attr => 'value')
105
106
  end
106
107
 
107
- it "should use Proxy::Create for Factory.create" do
108
+ it "uses Proxy::Create for Factory.create" do
108
109
  @factory.stubs(:run => "result")
109
110
  Factory.create(@name, :attr => 'value').should == 'result'
110
111
  @factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value')
111
112
  end
112
113
 
113
- it "should use Proxy::Stub for Factory.stub" do
114
+ it "uses Proxy::Stub for Factory.stub" do
114
115
  @factory.stubs(:run => "result")
115
116
  Factory.stub(@name, :attr => 'value').should == 'result'
116
117
  @factory.should have_received(:run).with(FactoryGirl::Proxy::Stub, :attr => 'value')
117
118
  end
118
119
 
119
- it "should use default strategy option as Factory.default_strategy" do
120
+ it "uses default strategy option as Factory.default_strategy" do
120
121
  @factory.stubs(:default_strategy => :create, :run => "result")
121
122
  Factory.default_strategy(@name, :attr => 'value').should == 'result'
122
123
  @factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value')
123
124
  end
124
125
 
125
- it "should use the default strategy for the global Factory method" do
126
+ it "uses the default strategy for the global Factory method" do
126
127
  @factory.stubs(:default_strategy => :create, :run => "result")
127
128
  Factory(@name, :attr => 'value').should == 'result'
128
129
  @factory.should have_received(:run).with(FactoryGirl::Proxy::Create, :attr => 'value')
129
130
  end
130
131
 
131
132
  [:build, :create, :attributes_for, :stub].each do |method|
132
- it "should raise an ArgumentError on #{method} with a nonexistent factory" do
133
- lambda { Factory.send(method, :bogus) }.should raise_error(ArgumentError)
133
+ it "raises an ArgumentError on #{method} with a nonexistent factory" do
134
+ expect { Factory.send(method, :bogus) }.to raise_error(ArgumentError)
134
135
  end
135
136
 
136
- it "should recognize either 'name' or :name for Factory.#{method}" do
137
+ it "recognizes either 'name' or :name for Factory.#{method}" do
137
138
  @factory.stubs(:run)
138
139
  lambda { Factory.send(method, @name.to_s) }.should_not raise_error
139
140
  lambda { Factory.send(method, @name.to_sym) }.should_not raise_error
@@ -146,17 +147,17 @@ describe "defining a sequence" do
146
147
  @name = :count
147
148
  end
148
149
 
149
- it "should create a new sequence" do
150
+ it "creates a new sequence" do
150
151
  Factory.sequence(@name)
151
152
  Factory.next(@name).should == 1
152
153
  end
153
154
 
154
- it "should use the supplied block as the sequence generator" do
155
+ it "uses the supplied block as the sequence generator" do
155
156
  Factory.sequence(@name) {|n| "user-#{n}" }
156
157
  Factory.next(@name).should == "user-1"
157
158
  end
158
159
 
159
- it "should use the supplied start_value as the sequence start_value" do
160
+ it "uses the supplied start_value as the sequence start_value" do
160
161
  Factory.sequence(@name, "A")
161
162
  Factory.next(@name).should == "A"
162
163
  end
@@ -174,12 +175,12 @@ describe "after defining a sequence" do
174
175
  Factory.sequence(@name) {}
175
176
  end
176
177
 
177
- it "should call next on the sequence when sent next" do
178
+ it "calls next on the sequence when sent next" do
178
179
  Factory.next(@name)
179
180
  @sequence.should have_received(:next)
180
181
  end
181
182
 
182
- it "should return the value from the sequence" do
183
+ it "returns the value from the sequence" do
183
184
  Factory.next(@name).should == @value
184
185
  end
185
186
  end
@@ -195,7 +196,7 @@ describe "an attribute generated by an in-line sequence" do
195
196
  @username = Factory.attributes_for(:user)[:username]
196
197
  end
197
198
 
198
- it "should match the correct format" do
199
+ it "matches the correct format" do
199
200
  @username.should =~ /^username\d+$/
200
201
  end
201
202
 
@@ -204,11 +205,11 @@ describe "an attribute generated by an in-line sequence" do
204
205
  @another_username = Factory.attributes_for(:user)[:username]
205
206
  end
206
207
 
207
- it "should match the correct format" do
208
+ it "matches the correct format" do
208
209
  @username.should =~ /^username\d+$/
209
210
  end
210
211
 
211
- it "should not be the same as the first generated value" do
212
+ it "is not the same as the first generated value" do
212
213
  @another_username.should_not == @username
213
214
  end
214
215
  end
@@ -8,9 +8,11 @@ describe "transient attributes" do
8
8
  sequence(:name) {|n| "John #{n}" }
9
9
 
10
10
  factory :user do
11
- four { 2 + 2 }.ignore
12
- rockstar(true).ignore
13
- upcased(false).ignore
11
+ ignore do
12
+ four { 2 + 2 }
13
+ rockstar true
14
+ upcased false
15
+ end
14
16
 
15
17
  name { "#{FactoryGirl.generate(:name)}#{" - Rockstar" if rockstar}" }
16
18
  email { "#{name.downcase}#{four}@example.com" }
@@ -66,3 +68,43 @@ describe "transient attributes" do
66
68
  end
67
69
  end
68
70
  end
71
+
72
+ describe "deprecated way of ignoring attributes" do
73
+ before do
74
+ define_model("User", :name => :string)
75
+
76
+ FactoryGirl.define do
77
+ factory :user do
78
+ rockstar(false).ignore
79
+
80
+ name { "John Doe#{" Rockstar" if rockstar}" }
81
+ end
82
+ end
83
+ end
84
+
85
+ it "assigns attributes correctly" do
86
+ FactoryGirl.build(:user, :rockstar => true).name.should == "John Doe Rockstar"
87
+ FactoryGirl.build(:user).name.should == "John Doe"
88
+ end
89
+ end
90
+
91
+ describe "transient sequences" do
92
+ before do
93
+ define_model("User", :name => :string)
94
+
95
+ FactoryGirl.define do
96
+ factory :user do
97
+ ignore do
98
+ sequence(:counter)
99
+ end
100
+
101
+ name { "John Doe #{counter}" }
102
+ end
103
+ end
104
+ end
105
+
106
+ it "increments sequences correctly" do
107
+ FactoryGirl.build(:user).name.should == "John Doe 1"
108
+ FactoryGirl.build(:user).name.should == "John Doe 2"
109
+ end
110
+ end
@@ -5,7 +5,7 @@ describe FactoryGirl::Attribute::Dynamic do
5
5
  let(:proxy) { stub("proxy", :set => nil) }
6
6
  let(:block) { lambda { } }
7
7
 
8
- subject { FactoryGirl::Attribute::Dynamic.new(name, block) }
8
+ subject { FactoryGirl::Attribute::Dynamic.new(name, false, block) }
9
9
 
10
10
  its(:name) { should == name }
11
11
 
@@ -14,7 +14,7 @@ describe FactoryGirl::Attribute::Dynamic do
14
14
 
15
15
  it "calls the block to set a value" do
16
16
  subject.add_to(proxy)
17
- proxy.should have_received(:set).with(name, "value", false)
17
+ proxy.should have_received(:set).with(name, "value")
18
18
  end
19
19
  end
20
20
 
@@ -23,7 +23,7 @@ describe FactoryGirl::Attribute::Dynamic do
23
23
 
24
24
  it "yields the proxy to the block" do
25
25
  subject.add_to(proxy)
26
- proxy.should have_received(:set).with(name, proxy, false)
26
+ proxy.should have_received(:set).with(name, proxy)
27
27
  end
28
28
  end
29
29
 
@@ -37,7 +37,7 @@ describe FactoryGirl::Attribute::Dynamic do
37
37
 
38
38
  it "evaluates the attribute from the proxy" do
39
39
  subject.add_to(proxy)
40
- proxy.should have_received(:set).with(name, result, false)
40
+ proxy.should have_received(:set).with(name, result)
41
41
  end
42
42
  end
43
43
 
@@ -51,6 +51,6 @@ describe FactoryGirl::Attribute::Dynamic do
51
51
  end
52
52
 
53
53
  describe FactoryGirl::Attribute::Dynamic, "with a string name" do
54
- subject { FactoryGirl::Attribute::Dynamic.new("name", nil) }
54
+ subject { FactoryGirl::Attribute::Dynamic.new("name", nil, false) }
55
55
  its(:name) { should == :name }
56
56
  end
@@ -6,7 +6,7 @@ describe FactoryGirl::Attribute::Sequence do
6
6
  let(:sequence) { FactoryGirl::Sequence.new(sequence_name, 5) { |n| "Name #{n}" } }
7
7
  let(:proxy) { stub("proxy") }
8
8
 
9
- subject { FactoryGirl::Attribute::Sequence.new(name, sequence_name) }
9
+ subject { FactoryGirl::Attribute::Sequence.new(name, sequence_name, false) }
10
10
  before { FactoryGirl.register_sequence(sequence) }
11
11
 
12
12
  its(:name) { should == name }
@@ -5,18 +5,18 @@ describe FactoryGirl::Attribute::Static do
5
5
  let(:value) { "John" }
6
6
  let(:proxy) { stub("proxy") }
7
7
 
8
- subject { FactoryGirl::Attribute::Static.new(name, value) }
8
+ subject { FactoryGirl::Attribute::Static.new(name, value, false) }
9
9
 
10
10
  its(:name) { should == name }
11
11
 
12
12
  it "sets its static value on a proxy" do
13
13
  proxy.stubs(:set)
14
14
  subject.add_to(proxy)
15
- proxy.should have_received(:set).with(name, value, false)
15
+ proxy.should have_received(:set).with(name, value)
16
16
  end
17
17
  end
18
18
 
19
19
  describe FactoryGirl::Attribute::Static, "with a string name" do
20
- subject { FactoryGirl::Attribute::Static.new("name", nil) }
20
+ subject { FactoryGirl::Attribute::Static.new("name", nil, false) }
21
21
  its(:name) { should == :name }
22
22
  end
@@ -10,8 +10,8 @@ describe FactoryGirl::AttributeList, "overridable" do
10
10
  end
11
11
 
12
12
  describe FactoryGirl::AttributeList, "#define_attribute" do
13
- let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value") }
14
- let(:dynamic_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, lambda {|u| "#{u.full_name}@example.com" }) }
13
+ let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value", false) }
14
+ let(:dynamic_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, lambda {|u| "#{u.full_name}@example.com" }) }
15
15
 
16
16
  it "maintains a list of attributes" do
17
17
  subject.define_attribute(static_attribute)
@@ -33,7 +33,7 @@ describe FactoryGirl::AttributeList, "#define_attribute" do
33
33
  end
34
34
 
35
35
  context "when set as overridable" do
36
- let(:static_attribute_with_same_name) { FactoryGirl::Attribute::Static.new(:full_name, "overridden value") }
36
+ let(:static_attribute_with_same_name) { FactoryGirl::Attribute::Static.new(:full_name, "overridden value", false) }
37
37
  before { subject.overridable }
38
38
 
39
39
  it "redefines the attribute if the name already exists" do
@@ -45,21 +45,6 @@ describe FactoryGirl::AttributeList, "#define_attribute" do
45
45
  end
46
46
  end
47
47
 
48
- describe FactoryGirl::AttributeList, "#attribute_defined?" do
49
- let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value") }
50
- let(:callback_attribute) { FactoryGirl::Callback.new(:after_create, lambda { }) }
51
- let(:static_attribute_named_after_create) { FactoryGirl::Attribute::Static.new(:after_create, "funky!") }
52
-
53
- it "knows if an attribute has been defined" do
54
- subject.attribute_defined?(static_attribute.name).should == false
55
-
56
- subject.define_attribute(static_attribute)
57
-
58
- subject.attribute_defined?(static_attribute.name).should == true
59
- subject.attribute_defined?(:undefined_attribute).should == false
60
- end
61
- end
62
-
63
48
  describe FactoryGirl::AttributeList, "#add_callback" do
64
49
  let(:proxy_class) { mock("klass") }
65
50
  let(:proxy) { FactoryGirl::Proxy.new(proxy_class) }
@@ -73,10 +58,10 @@ describe FactoryGirl::AttributeList, "#add_callback" do
73
58
  end
74
59
 
75
60
  describe FactoryGirl::AttributeList, "#apply_attributes" do
76
- let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "John Adams") }
77
- let(:city_attribute) { FactoryGirl::Attribute::Static.new(:city, "Boston") }
78
- let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, lambda {|model| "#{model.full_name}@example.com" }) }
79
- let(:login_attribute) { FactoryGirl::Attribute::Dynamic.new(:login, lambda {|model| "username-#{model.full_name}" }) }
61
+ let(:full_name_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "John Adams", false) }
62
+ let(:city_attribute) { FactoryGirl::Attribute::Static.new(:city, "Boston", false) }
63
+ let(:email_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, lambda {|model| "#{model.full_name}@example.com" }) }
64
+ let(:login_attribute) { FactoryGirl::Attribute::Dynamic.new(:login, false, lambda {|model| "username-#{model.full_name}" }) }
80
65
 
81
66
  def list(*attributes)
82
67
  FactoryGirl::AttributeList.new.tap do |list|
@@ -105,7 +90,7 @@ describe FactoryGirl::AttributeList, "#apply_attributes" do
105
90
 
106
91
  it "doesn't overwrite attributes that are already defined" do
107
92
  subject.define_attribute(full_name_attribute)
108
- attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin")
93
+ attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin", false)
109
94
 
110
95
  subject.apply_attributes(list(attribute_with_same_name))
111
96
  subject.to_a.should == [full_name_attribute]
@@ -135,7 +120,7 @@ describe FactoryGirl::AttributeList, "#apply_attributes" do
135
120
 
136
121
  it "overwrites attributes that are already defined" do
137
122
  subject.define_attribute(full_name_attribute)
138
- attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin")
123
+ attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin", false)
139
124
 
140
125
  subject.apply_attributes(list(attribute_with_same_name))
141
126
  subject.to_a.should == [attribute_with_same_name]
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe FactoryGirl::Attribute do
4
4
  let(:name) { "user" }
5
5
  let(:proxy) { stub("proxy") }
6
- subject { FactoryGirl::Attribute.new(name) }
6
+ subject { FactoryGirl::Attribute.new(name, false) }
7
7
 
8
8
  its(:name) { should == name.to_sym }
9
9
  it { should_not be_association }
@@ -17,7 +17,7 @@ describe FactoryGirl::Attribute do
17
17
  it "raises an error when defining an attribute writer" do
18
18
  error_message = %{factory_girl uses 'f.test value' syntax rather than 'f.test = value'}
19
19
  expect {
20
- FactoryGirl::Attribute.new('test=')
20
+ FactoryGirl::Attribute.new('test=', false)
21
21
  }.to raise_error(FactoryGirl::AttributeDefinitionError, error_message)
22
22
  end
23
23
 
@@ -26,7 +26,7 @@ describe FactoryGirl::Attribute do
26
26
  end
27
27
 
28
28
  it "uses priority to perform comparisons" do
29
- second_attribute = FactoryGirl::Attribute.new('name')
29
+ second_attribute = FactoryGirl::Attribute.new('name', false)
30
30
  (subject <=> second_attribute).should be_zero
31
31
  end
32
32
  end
@@ -4,56 +4,37 @@ describe FactoryGirl::DefinitionProxy do
4
4
  let(:factory) { FactoryGirl::Factory.new(:object) }
5
5
  subject { FactoryGirl::DefinitionProxy.new(factory) }
6
6
 
7
- def attributes
8
- factory.attributes
9
- end
10
-
11
- it "should add a static attribute for type" do
12
- subject.type 'value'
13
- attributes.to_a.last.should be_kind_of(FactoryGirl::Attribute::Static)
14
- end
15
-
16
- it "should add a static attribute for id" do
17
- subject.id 'value'
18
- attributes.to_a.last.should be_kind_of(FactoryGirl::Attribute::Static)
19
- end
20
-
21
- it "should add a static attribute when an attribute is defined with a value" do
7
+ it "adds a static attribute when an attribute is defined with a value" do
22
8
  attribute = stub('attribute', :name => :name)
23
9
  FactoryGirl::Attribute::Static.stubs(:new => attribute)
24
10
  factory.stubs(:define_attribute)
25
11
  subject.add_attribute(:name, 'value')
26
- factory.compile
12
+ factory.ensure_compiled
27
13
  factory.should have_received(:define_attribute).with(attribute)
28
- FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value")
14
+ FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value", false)
29
15
  end
30
16
 
31
- it "should add a dynamic attribute when an attribute is defined with a block" do
17
+ it "adds a dynamic attribute when an attribute is defined with a block" do
32
18
  attribute = stub('attribute', :name => :name)
33
19
  block = lambda {}
34
20
  FactoryGirl::Attribute::Dynamic.stubs(:new => attribute)
35
21
  factory.stubs(:define_attribute)
36
22
  subject.add_attribute(:name, &block)
37
- factory.compile
38
- FactoryGirl::Attribute::Dynamic.should have_received(:new).with(:name, block)
23
+ factory.ensure_compiled
24
+ FactoryGirl::Attribute::Dynamic.should have_received(:new).with(:name, false, block)
39
25
  factory.should have_received(:define_attribute).with(attribute)
40
26
  end
41
27
 
42
- it "should raise for an attribute with a value and a block" do
43
- lambda {
28
+ it "raises for an attribute with a value and a block" do
29
+ expect {
44
30
  subject.add_attribute(:name, 'value') {}
45
- }.should raise_error(FactoryGirl::AttributeDefinitionError)
46
- end
47
-
48
- it "should add an attribute with a built-in private method" do
49
- subject.instance_eval { sleep(0.1) }
50
- attributes.map { |attribute| attribute.name }.should == [:sleep]
31
+ }.to raise_error(FactoryGirl::AttributeDefinitionError)
51
32
  end
52
33
 
53
34
  describe "child factories" do
54
35
  its(:child_factories) { should == [] }
55
36
 
56
- it "should be able to add child factories" do
37
+ it "is be able to add child factories" do
57
38
  block = lambda {}
58
39
  subject.factory(:admin, { :aliases => [:great] }, &block)
59
40
  subject.child_factories.should == [[:admin, { :aliases => [:great] }, block]]
@@ -61,13 +42,13 @@ describe FactoryGirl::DefinitionProxy do
61
42
  end
62
43
 
63
44
  describe "adding an attribute using a in-line sequence" do
64
- it "should create the sequence" do
45
+ it "creates the sequence" do
65
46
  FactoryGirl::Sequence.stubs(:new)
66
47
  subject.sequence(:name) {}
67
48
  FactoryGirl::Sequence.should have_received(:new).with(:name, 1)
68
49
  end
69
50
 
70
- it "should create the sequence with a custom default value" do
51
+ it "creates the sequence with a custom default value" do
71
52
  FactoryGirl::Sequence.stubs(:new)
72
53
  subject.sequence(:name, "A") {}
73
54
  FactoryGirl::Sequence.should have_received(:new).with(:name, "A")
@@ -123,15 +104,15 @@ describe FactoryGirl::DefinitionProxy, "adding attributes" do
123
104
 
124
105
  it "creates a dynamic attribute" do
125
106
  subject.add_attribute(attribute_name, &block)
126
- factory.compile
127
- FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, block)
107
+ factory.ensure_compiled
108
+ FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, false, block)
128
109
  factory.should have_received(:define_attribute).with(attribute)
129
110
  end
130
111
 
131
112
  it "creates a dynamic attribute without the method being defined" do
132
113
  subject.send(attribute_name, &block)
133
- factory.compile
134
- FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, block)
114
+ factory.ensure_compiled
115
+ FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, false, block)
135
116
  factory.should have_received(:define_attribute).with(attribute)
136
117
  end
137
118
  end
@@ -141,15 +122,15 @@ describe FactoryGirl::DefinitionProxy, "adding attributes" do
141
122
 
142
123
  it "creates a static attribute" do
143
124
  subject.add_attribute(attribute_name, attribute_value)
144
- factory.compile
145
- FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value)
125
+ factory.ensure_compiled
126
+ FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value, false)
146
127
  factory.should have_received(:define_attribute).with(attribute)
147
128
  end
148
129
 
149
130
  it "creates a static attribute without the method being defined" do
150
131
  subject.send(attribute_name, attribute_value)
151
- factory.compile
152
- FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value)
132
+ factory.ensure_compiled
133
+ FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value, false)
153
134
  factory.should have_received(:define_attribute).with(attribute)
154
135
  end
155
136
  end
@@ -180,7 +161,7 @@ describe FactoryGirl::DefinitionProxy, "#association" do
180
161
 
181
162
  it "defines an association attribute with the factory name" do
182
163
  subject.association(association_name, options)
183
- factory.compile
164
+ factory.ensure_compiled
184
165
 
185
166
  factory.should have_received(:define_attribute).with(attribute)
186
167
  FactoryGirl::Attribute::Association.should have_received(:new).with(association_name, factory_name, :name => "John Doe")
@@ -188,7 +169,7 @@ describe FactoryGirl::DefinitionProxy, "#association" do
188
169
 
189
170
  it "defines an association attribute when the association is called implicitly" do
190
171
  subject.send(association_name, options)
191
- factory.compile
172
+ factory.ensure_compiled
192
173
 
193
174
  factory.should have_received(:define_attribute).with(attribute)
194
175
  FactoryGirl::Attribute::Association.should have_received(:new).with(association_name, factory_name, :name => "John Doe")
@@ -200,7 +181,7 @@ describe FactoryGirl::DefinitionProxy, "#association" do
200
181
 
201
182
  it "defines an association attribute with the association name" do
202
183
  subject.association(association_name, options)
203
- factory.compile
184
+ factory.ensure_compiled
204
185
 
205
186
  factory.should have_received(:define_attribute).with(attribute)
206
187
  FactoryGirl::Attribute::Association.should have_received(:new).with(association_name, association_name, options)