factory_girl 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -1
- data/CONTRIBUTION_GUIDELINES.md +1 -1
- data/Changelog +16 -3
- data/GETTING_STARTED.md +22 -2
- data/Gemfile.lock +1 -1
- data/Rakefile +11 -15
- data/gemfiles/2.1.gemfile.lock +1 -1
- data/gemfiles/2.3.gemfile.lock +1 -1
- data/gemfiles/3.0.gemfile.lock +1 -1
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/lib/factory_girl.rb +8 -3
- data/lib/factory_girl/attribute.rb +8 -0
- data/lib/factory_girl/attribute/dynamic.rb +1 -5
- data/lib/factory_girl/attribute/sequence.rb +1 -5
- data/lib/factory_girl/attribute/static.rb +1 -5
- data/lib/factory_girl/attribute_list.rb +18 -44
- data/lib/factory_girl/callback.rb +5 -0
- data/lib/factory_girl/declaration.rb +3 -0
- data/lib/factory_girl/declaration/association.rb +8 -0
- data/lib/factory_girl/declaration/dynamic.rb +9 -0
- data/lib/factory_girl/declaration/implicit.rb +11 -2
- data/lib/factory_girl/declaration/static.rb +9 -0
- data/lib/factory_girl/declaration_list.rb +48 -0
- data/lib/factory_girl/definition.rb +62 -0
- data/lib/factory_girl/definition_proxy.rb +11 -11
- data/lib/factory_girl/factory.rb +100 -111
- data/lib/factory_girl/null_factory.rb +15 -0
- data/lib/factory_girl/proxy.rb +14 -9
- data/lib/factory_girl/proxy/attributes_for.rb +2 -3
- data/lib/factory_girl/proxy/build.rb +12 -20
- data/lib/factory_girl/proxy/create.rb +0 -6
- data/lib/factory_girl/proxy/stub.rb +4 -10
- data/lib/factory_girl/registry.rb +4 -3
- data/lib/factory_girl/step_definitions.rb +1 -1
- data/lib/factory_girl/syntax/default.rb +3 -4
- data/lib/factory_girl/syntax/methods.rb +38 -16
- data/lib/factory_girl/trait.rb +13 -21
- data/lib/factory_girl/version.rb +1 -1
- data/spec/acceptance/modify_factories_spec.rb +1 -1
- data/spec/acceptance/traits_spec.rb +87 -1
- data/spec/factory_girl/attribute/dynamic_spec.rb +1 -1
- data/spec/factory_girl/attribute_list_spec.rb +9 -58
- data/spec/factory_girl/declaration_list_spec.rb +71 -0
- data/spec/factory_girl/definition_proxy_spec.rb +135 -139
- data/spec/factory_girl/definition_spec.rb +81 -0
- data/spec/factory_girl/factory_spec.rb +42 -17
- data/spec/factory_girl/null_factory_spec.rb +12 -0
- data/spec/factory_girl/proxy/build_spec.rb +1 -24
- data/spec/factory_girl/proxy/create_spec.rb +14 -11
- data/spec/factory_girl/proxy_spec.rb +23 -40
- data/spec/factory_girl/registry_spec.rb +4 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/matchers/callback.rb +9 -0
- data/spec/support/matchers/declaration.rb +71 -0
- data/spec/support/matchers/delegate.rb +44 -0
- data/spec/support/matchers/trait.rb +9 -0
- data/spec/support/shared_examples/proxy.rb +4 -5
- metadata +191 -115
@@ -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",
|
54
|
+
subject { FactoryGirl::Attribute::Dynamic.new("name", false, lambda { } ) }
|
55
55
|
its(:name) { should == :name }
|
56
56
|
end
|
@@ -1,14 +1,5 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe FactoryGirl::AttributeList, "overridable" do
|
4
|
-
it { should_not be_overridable }
|
5
|
-
|
6
|
-
it "can set itself as overridable" do
|
7
|
-
subject.overridable
|
8
|
-
subject.should be_overridable
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
3
|
describe FactoryGirl::AttributeList, "#define_attribute" do
|
13
4
|
let(:static_attribute) { FactoryGirl::Attribute::Static.new(:full_name, "value", false) }
|
14
5
|
let(:dynamic_attribute) { FactoryGirl::Attribute::Dynamic.new(:email, false, lambda {|u| "#{u.full_name}@example.com" }) }
|
@@ -31,29 +22,20 @@ describe FactoryGirl::AttributeList, "#define_attribute" do
|
|
31
22
|
2.times { subject.define_attribute(static_attribute) }
|
32
23
|
}.to raise_error(FactoryGirl::AttributeDefinitionError, "Attribute already defined: full_name")
|
33
24
|
end
|
25
|
+
end
|
34
26
|
|
35
|
-
|
36
|
-
|
37
|
-
before { subject.overridable }
|
27
|
+
describe FactoryGirl::AttributeList, "#define_attribute with a named attribute list" do
|
28
|
+
subject { FactoryGirl::AttributeList.new(:author) }
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
subject.define_attribute(static_attribute_with_same_name)
|
30
|
+
let(:association_with_same_name) { FactoryGirl::Attribute::Association.new(:author, :author, {}) }
|
31
|
+
let(:association_with_different_name) { FactoryGirl::Attribute::Association.new(:author, :post, {}) }
|
42
32
|
|
43
|
-
|
44
|
-
|
33
|
+
it "raises when the attribute is a self-referencing association" do
|
34
|
+
expect { subject.define_attribute(association_with_same_name) }.to raise_error(FactoryGirl::AssociationDefinitionError, "Self-referencing association 'author' in 'author'")
|
45
35
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe FactoryGirl::AttributeList, "#add_callback" do
|
49
|
-
let(:proxy_class) { mock("klass") }
|
50
|
-
let(:proxy) { FactoryGirl::Proxy.new(proxy_class) }
|
51
36
|
|
52
|
-
it "
|
53
|
-
subject.
|
54
|
-
|
55
|
-
subject.callbacks.first.name.should == :after_create
|
56
|
-
subject.callbacks.first.run(nil, nil).should == "Called after_create"
|
37
|
+
it "does not raise when the attribute is not a self-referencing association" do
|
38
|
+
expect { subject.define_attribute(association_with_different_name) }.to_not raise_error
|
57
39
|
end
|
58
40
|
end
|
59
41
|
|
@@ -95,35 +77,4 @@ describe FactoryGirl::AttributeList, "#apply_attributes" do
|
|
95
77
|
subject.apply_attributes(list(attribute_with_same_name))
|
96
78
|
subject.to_a.should == [full_name_attribute]
|
97
79
|
end
|
98
|
-
|
99
|
-
context "when set as overridable" do
|
100
|
-
before { subject.overridable }
|
101
|
-
|
102
|
-
it "prepends applied attributes" do
|
103
|
-
subject.define_attribute(full_name_attribute)
|
104
|
-
subject.apply_attributes(list(city_attribute))
|
105
|
-
subject.to_a.should == [city_attribute, full_name_attribute]
|
106
|
-
end
|
107
|
-
|
108
|
-
it "moves non-static attributes to the end of the list" do
|
109
|
-
subject.define_attribute(full_name_attribute)
|
110
|
-
subject.apply_attributes(list(city_attribute, email_attribute))
|
111
|
-
subject.to_a.should == [city_attribute, full_name_attribute, email_attribute]
|
112
|
-
end
|
113
|
-
|
114
|
-
it "maintains order of non-static attributes" do
|
115
|
-
subject.define_attribute(full_name_attribute)
|
116
|
-
subject.define_attribute(login_attribute)
|
117
|
-
subject.apply_attributes(list(city_attribute, email_attribute))
|
118
|
-
subject.to_a.should == [city_attribute, full_name_attribute, email_attribute, login_attribute]
|
119
|
-
end
|
120
|
-
|
121
|
-
it "overwrites attributes that are already defined" do
|
122
|
-
subject.define_attribute(full_name_attribute)
|
123
|
-
attribute_with_same_name = FactoryGirl::Attribute::Static.new(:full_name, "Benjamin Franklin", false)
|
124
|
-
|
125
|
-
subject.apply_attributes(list(attribute_with_same_name))
|
126
|
-
subject.to_a.should == [attribute_with_same_name]
|
127
|
-
end
|
128
|
-
end
|
129
80
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FactoryGirl::DeclarationList, "#attribute_list" do
|
4
|
+
let(:static_attribute_1) { stub("static attribute 1") }
|
5
|
+
let(:static_attribute_2) { stub("static attribute 2") }
|
6
|
+
let(:dynamic_attribute_1) { stub("dynamic attribute 1") }
|
7
|
+
let(:static_declaration) { stub("static declaration", :to_attributes => [static_attribute_1, static_attribute_2]) }
|
8
|
+
let(:dynamic_declaration) { stub("static declaration", :to_attributes => [dynamic_attribute_1]) }
|
9
|
+
|
10
|
+
it "returns an AttributeList" do
|
11
|
+
subject.attribute_list.should be_a(FactoryGirl::AttributeList)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:attribute_list) { stub("attribute list", :define_attribute => true) }
|
15
|
+
|
16
|
+
it "defines each attribute on the attribute list" do
|
17
|
+
FactoryGirl::AttributeList.stubs(:new => attribute_list)
|
18
|
+
|
19
|
+
subject.declare_attribute(static_declaration)
|
20
|
+
subject.declare_attribute(dynamic_declaration)
|
21
|
+
|
22
|
+
subject.attribute_list
|
23
|
+
|
24
|
+
attribute_list.should have_received(:define_attribute).with(static_attribute_1)
|
25
|
+
attribute_list.should have_received(:define_attribute).with(static_attribute_2)
|
26
|
+
attribute_list.should have_received(:define_attribute).with(dynamic_attribute_1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "creates a new attribute list upon every invocation" do
|
30
|
+
subject.attribute_list.should_not == subject.attribute_list
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe FactoryGirl::DeclarationList, "#declare_attribute" do
|
35
|
+
let(:declaration_1) { stub("declaration", :name => "declaration 1") }
|
36
|
+
let(:declaration_2) { stub("declaration", :name => "declaration 2") }
|
37
|
+
let(:declaration_with_same_name) { stub("declaration", :name => "declaration 1") }
|
38
|
+
|
39
|
+
context "when not overridable" do
|
40
|
+
it "adds the declaration to the list" do
|
41
|
+
subject.declare_attribute(declaration_1)
|
42
|
+
subject.to_a.should == [declaration_1]
|
43
|
+
|
44
|
+
subject.declare_attribute(declaration_2)
|
45
|
+
subject.to_a.should == [declaration_1, declaration_2]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when overridable" do
|
50
|
+
before { subject.overridable }
|
51
|
+
|
52
|
+
it "adds the declaration to the list" do
|
53
|
+
subject.declare_attribute(declaration_1)
|
54
|
+
subject.to_a.should == [declaration_1]
|
55
|
+
|
56
|
+
subject.declare_attribute(declaration_2)
|
57
|
+
subject.to_a.should == [declaration_1, declaration_2]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "deletes declarations with the same name" do
|
61
|
+
subject.declare_attribute(declaration_1)
|
62
|
+
subject.to_a.should == [declaration_1]
|
63
|
+
|
64
|
+
subject.declare_attribute(declaration_2)
|
65
|
+
subject.to_a.should == [declaration_1, declaration_2]
|
66
|
+
|
67
|
+
subject.declare_attribute(declaration_with_same_name)
|
68
|
+
subject.to_a.should == [declaration_2, declaration_with_same_name]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,190 +1,186 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe FactoryGirl::DefinitionProxy do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
it "
|
8
|
-
attribute = stub('attribute', :name => :name)
|
9
|
-
FactoryGirl::Attribute::Static.stubs(:new => attribute)
|
10
|
-
factory.stubs(:define_attribute)
|
11
|
-
subject.add_attribute(:name, 'value')
|
12
|
-
factory.ensure_compiled
|
13
|
-
factory.should have_received(:define_attribute).with(attribute)
|
14
|
-
FactoryGirl::Attribute::Static.should have_received(:new).with(:name, "value", false)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "adds a dynamic attribute when an attribute is defined with a block" do
|
18
|
-
attribute = stub('attribute', :name => :name)
|
19
|
-
block = lambda {}
|
20
|
-
FactoryGirl::Attribute::Dynamic.stubs(:new => attribute)
|
21
|
-
factory.stubs(:define_attribute)
|
22
|
-
subject.add_attribute(:name, &block)
|
23
|
-
factory.ensure_compiled
|
24
|
-
FactoryGirl::Attribute::Dynamic.should have_received(:new).with(:name, false, block)
|
25
|
-
factory.should have_received(:define_attribute).with(attribute)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "raises for an attribute with a value and a block" do
|
3
|
+
describe FactoryGirl::DefinitionProxy, "#add_attribute" do
|
4
|
+
subject { FactoryGirl::Definition.new }
|
5
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
6
|
+
|
7
|
+
it "raises if both a block and value are given" do
|
29
8
|
expect {
|
30
|
-
|
31
|
-
}.to raise_error(FactoryGirl::AttributeDefinitionError)
|
9
|
+
proxy.add_attribute(:something, "great") { "will raise!" }
|
10
|
+
}.to raise_error(FactoryGirl::AttributeDefinitionError, "Both value and block given")
|
32
11
|
end
|
33
12
|
|
34
|
-
|
35
|
-
|
13
|
+
it "declares a static attribute on the factory" do
|
14
|
+
proxy.add_attribute(:attribute_name, "attribute value")
|
15
|
+
subject.should have_static_declaration(:attribute_name).with_value("attribute value")
|
16
|
+
end
|
36
17
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
18
|
+
it "declares a dynamic attribute on the factory" do
|
19
|
+
attribute_value = lambda { "dynamic attribute" }
|
20
|
+
proxy.add_attribute(:attribute_name, &attribute_value)
|
21
|
+
subject.should have_dynamic_declaration(:attribute_name).with_value(attribute_value)
|
42
22
|
end
|
23
|
+
end
|
43
24
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
subject.sequence(:name) {}
|
48
|
-
FactoryGirl::Sequence.should have_received(:new).with(:name, 1)
|
49
|
-
end
|
25
|
+
describe FactoryGirl::DefinitionProxy, "#add_attribute when the proxy ignores attributes" do
|
26
|
+
subject { FactoryGirl::Definition.new }
|
27
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject, true) }
|
50
28
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
29
|
+
it "raises if both a block and value are given" do
|
30
|
+
expect {
|
31
|
+
proxy.add_attribute(:something, "great") { "will raise!" }
|
32
|
+
}.to raise_error(FactoryGirl::AttributeDefinitionError, "Both value and block given")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "declares a static attribute on the factory" do
|
36
|
+
proxy.add_attribute(:attribute_name, "attribute value")
|
37
|
+
subject.should have_static_declaration(:attribute_name).ignored.with_value("attribute value")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "declares a dynamic attribute on the factory" do
|
41
|
+
attribute_value = lambda { "dynamic attribute" }
|
42
|
+
proxy.add_attribute(:attribute_name, &attribute_value)
|
43
|
+
subject.should have_dynamic_declaration(:attribute_name).ignored.with_value(attribute_value)
|
56
44
|
end
|
57
45
|
end
|
58
46
|
|
59
|
-
describe FactoryGirl::DefinitionProxy, "
|
60
|
-
|
61
|
-
|
62
|
-
def add_callback(callback, &block)
|
63
|
-
[callback, block.call]
|
64
|
-
end
|
47
|
+
describe FactoryGirl::DefinitionProxy, "#ignore" do
|
48
|
+
subject { FactoryGirl::Definition.new }
|
49
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
65
50
|
|
66
|
-
|
67
|
-
|
68
|
-
|
51
|
+
it "makes all attributes added ignored" do
|
52
|
+
proxy.ignore do
|
53
|
+
add_attribute(:attribute_name, "attribute value")
|
69
54
|
end
|
55
|
+
|
56
|
+
subject.should have_static_declaration(:attribute_name).ignored.with_value("attribute value")
|
70
57
|
end
|
58
|
+
end
|
71
59
|
|
72
|
-
|
73
|
-
subject
|
60
|
+
describe FactoryGirl::DefinitionProxy, "#method_missing" do
|
61
|
+
subject { FactoryGirl::Definition.new }
|
62
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
74
63
|
|
75
|
-
it "
|
76
|
-
|
64
|
+
it "declares an implicit declaration without args or a block" do
|
65
|
+
proxy.bogus
|
66
|
+
subject.should have_implicit_declaration(:bogus).with_factory(subject)
|
77
67
|
end
|
78
68
|
|
79
|
-
it "
|
80
|
-
|
69
|
+
it "declares an association when :factory is passed" do
|
70
|
+
proxy.author :factory => :user
|
71
|
+
subject.should have_association_declaration(:author).with_options(:factory => :user)
|
81
72
|
end
|
82
73
|
|
83
|
-
it "
|
84
|
-
|
74
|
+
it "declares a static attribute" do
|
75
|
+
proxy.attribute_name "attribute value"
|
76
|
+
subject.should have_static_declaration(:attribute_name).with_value("attribute value")
|
85
77
|
end
|
86
78
|
|
87
|
-
it "
|
88
|
-
|
79
|
+
it "declares a dynamic attribute" do
|
80
|
+
attribute_value = lambda { "dynamic attribute" }
|
81
|
+
proxy.attribute_name &attribute_value
|
82
|
+
subject.should have_dynamic_declaration(:attribute_name).with_value(attribute_value)
|
89
83
|
end
|
90
84
|
end
|
91
85
|
|
92
|
-
describe FactoryGirl::DefinitionProxy, "
|
93
|
-
|
94
|
-
|
95
|
-
let(:attribute) { stub("created attribute") }
|
96
|
-
let(:block) { lambda { } }
|
97
|
-
let(:attribute_name) { :full_name }
|
98
|
-
let(:attribute_value) { "passed value" }
|
86
|
+
describe FactoryGirl::DefinitionProxy, "#sequence" do
|
87
|
+
subject { FactoryGirl::Definition.new }
|
88
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
99
89
|
|
100
|
-
before
|
90
|
+
before { FactoryGirl::Sequence.stubs(:new) }
|
101
91
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
subject.add_attribute(attribute_name, &block)
|
107
|
-
factory.ensure_compiled
|
108
|
-
FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, false, block)
|
109
|
-
factory.should have_received(:define_attribute).with(attribute)
|
110
|
-
end
|
92
|
+
it "creates a new sequence starting at 1" do
|
93
|
+
proxy.sequence(:great)
|
94
|
+
FactoryGirl::Sequence.should have_received(:new).with(:great, 1)
|
95
|
+
end
|
111
96
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
FactoryGirl::Attribute::Dynamic.should have_received(:new).with(attribute_name, false, block)
|
116
|
-
factory.should have_received(:define_attribute).with(attribute)
|
117
|
-
end
|
97
|
+
it "creates a new sequence with an overridden starting vaue" do
|
98
|
+
proxy.sequence(:great, "C")
|
99
|
+
FactoryGirl::Sequence.should have_received(:new).with(:great, "C")
|
118
100
|
end
|
119
101
|
|
120
|
-
|
121
|
-
|
102
|
+
it "creates a new sequence with a block" do
|
103
|
+
sequence_block = Proc.new {|n| "user+#{n}@example.com" }
|
104
|
+
proxy.sequence(:great, 1, &sequence_block)
|
105
|
+
FactoryGirl::Sequence.should have_received(:new).with(:great, 1, &sequence_block)
|
106
|
+
end
|
107
|
+
end
|
122
108
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value, false)
|
127
|
-
factory.should have_received(:define_attribute).with(attribute)
|
128
|
-
end
|
109
|
+
describe FactoryGirl::DefinitionProxy, "#association" do
|
110
|
+
subject { FactoryGirl::Definition.new }
|
111
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
129
112
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
FactoryGirl::Attribute::Static.should have_received(:new).with(attribute_name, attribute_value, false)
|
134
|
-
factory.should have_received(:define_attribute).with(attribute)
|
135
|
-
end
|
113
|
+
it "declares an association" do
|
114
|
+
proxy.association(:association_name)
|
115
|
+
subject.should have_association_declaration(:association_name)
|
136
116
|
end
|
137
117
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
subject.add_attribute(attribute_name, attribute_value) { "block" }
|
142
|
-
end.to raise_error(FactoryGirl::AttributeDefinitionError, "Both value and block given")
|
143
|
-
end
|
118
|
+
it "declares an association with options" do
|
119
|
+
proxy.association(:association_name, { :name => "Awesome" })
|
120
|
+
subject.should have_association_declaration(:association_name).with_options(:name => "Awesome")
|
144
121
|
end
|
145
122
|
end
|
146
123
|
|
147
|
-
describe FactoryGirl::DefinitionProxy, "
|
148
|
-
|
149
|
-
|
150
|
-
let(:
|
151
|
-
let(:association_name) { :author }
|
152
|
-
let(:factory_name) { :user }
|
124
|
+
describe FactoryGirl::DefinitionProxy, "adding callbacks" do
|
125
|
+
subject { FactoryGirl::Definition.new }
|
126
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
127
|
+
let(:callback) { lambda { "my awesome callback!" } }
|
153
128
|
|
154
|
-
|
155
|
-
|
156
|
-
|
129
|
+
context "#after_build" do
|
130
|
+
before { proxy.after_build(&callback) }
|
131
|
+
it { should have_callback(:after_build).with_block(callback) }
|
157
132
|
end
|
158
133
|
|
159
|
-
context "
|
160
|
-
|
134
|
+
context "#after_create" do
|
135
|
+
before { proxy.after_create(&callback) }
|
136
|
+
it { should have_callback(:after_create).with_block(callback) }
|
137
|
+
end
|
161
138
|
|
162
|
-
|
163
|
-
|
164
|
-
|
139
|
+
context "#after_stub" do
|
140
|
+
before { proxy.after_stub(&callback) }
|
141
|
+
it { should have_callback(:after_stub).with_block(callback) }
|
142
|
+
end
|
143
|
+
end
|
165
144
|
|
166
|
-
|
167
|
-
|
168
|
-
|
145
|
+
describe FactoryGirl::DefinitionProxy, "#to_create" do
|
146
|
+
subject { FactoryGirl::Definition.new }
|
147
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
169
148
|
|
170
|
-
|
171
|
-
|
172
|
-
|
149
|
+
it "accepts a block to run in place of #save!" do
|
150
|
+
to_create_block = lambda {|record| record.persist }
|
151
|
+
proxy.to_create(&to_create_block)
|
152
|
+
subject.to_create.should == to_create_block
|
153
|
+
end
|
154
|
+
end
|
173
155
|
|
174
|
-
|
175
|
-
|
176
|
-
|
156
|
+
describe FactoryGirl::DefinitionProxy, "#factory" do
|
157
|
+
subject { FactoryGirl::Definition.new }
|
158
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
159
|
+
|
160
|
+
it "without options" do
|
161
|
+
proxy.factory(:child)
|
162
|
+
proxy.child_factories.should include([:child, {}, nil])
|
177
163
|
end
|
178
164
|
|
179
|
-
|
180
|
-
|
165
|
+
it "with options" do
|
166
|
+
proxy.factory(:child, { :awesome => true })
|
167
|
+
proxy.child_factories.should include([:child, { :awesome => true }, nil])
|
168
|
+
end
|
181
169
|
|
182
|
-
|
183
|
-
|
184
|
-
|
170
|
+
it "with a block" do
|
171
|
+
child_block = lambda { }
|
172
|
+
proxy.factory(:child, {}, &child_block)
|
173
|
+
proxy.child_factories.should include([:child, {}, child_block])
|
174
|
+
end
|
175
|
+
end
|
185
176
|
|
186
|
-
|
187
|
-
|
188
|
-
|
177
|
+
describe FactoryGirl::DefinitionProxy, "#trait" do
|
178
|
+
subject { FactoryGirl::Definition.new }
|
179
|
+
let(:proxy) { FactoryGirl::DefinitionProxy.new(subject) }
|
180
|
+
|
181
|
+
it "declares a trait" do
|
182
|
+
male_trait = Proc.new { gender("Male") }
|
183
|
+
proxy.trait(:male, &male_trait)
|
184
|
+
subject.should have_trait(:male).with_block(male_trait)
|
189
185
|
end
|
190
186
|
end
|