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.
- checksums.yaml +4 -4
- data/.travis.yml +25 -5
- data/Appraisals +11 -7
- data/CONTRIBUTING.md +44 -6
- data/GETTING_STARTED.md +175 -59
- data/Gemfile +5 -0
- data/Gemfile.lock +86 -63
- data/LICENSE +1 -1
- data/NEWS +12 -1
- data/README.md +21 -10
- data/Rakefile +1 -3
- data/factory_girl.gemspec +6 -14
- data/gemfiles/3.2.gemfile +4 -1
- data/gemfiles/3.2.gemfile.lock +84 -52
- data/gemfiles/4.0.gemfile +4 -1
- data/gemfiles/4.0.gemfile.lock +75 -49
- data/gemfiles/4.1.gemfile +4 -1
- data/gemfiles/4.1.gemfile.lock +78 -48
- data/gemfiles/4.2.gemfile +10 -0
- data/gemfiles/4.2.gemfile.lock +123 -0
- data/gemfiles/5.0.gemfile +10 -0
- data/gemfiles/5.0.gemfile.lock +126 -0
- data/lib/factory_girl.rb +13 -4
- data/lib/factory_girl/attribute/dynamic.rb +4 -1
- data/lib/factory_girl/attribute_assigner.rb +2 -2
- data/lib/factory_girl/configuration.rb +4 -0
- data/lib/factory_girl/decorator.rb +2 -2
- data/lib/factory_girl/decorator/class_key_hash.rb +2 -1
- data/lib/factory_girl/definition_proxy.rb +2 -2
- data/lib/factory_girl/evaluator.rb +4 -0
- data/lib/factory_girl/factory_runner.rb +7 -1
- data/lib/factory_girl/find_definitions.rb +1 -1
- data/lib/factory_girl/linter.rb +65 -14
- data/lib/factory_girl/strategy/stub.rb +25 -1
- data/lib/factory_girl/strategy_syntax_method_registrar.rb +4 -0
- data/lib/factory_girl/version.rb +1 -1
- metadata +26 -185
- data/features/find_definitions.feature +0 -75
- data/features/step_definitions/database_steps.rb +0 -9
- data/features/step_definitions/factory_girl_steps.rb +0 -36
- data/features/support/env.rb +0 -10
- data/features/support/factories.rb +0 -16
- data/gemfiles/3.1.gemfile +0 -7
- data/gemfiles/3.1.gemfile.lock +0 -91
- data/spec/acceptance/activesupport_instrumentation_spec.rb +0 -62
- data/spec/acceptance/aliases_spec.rb +0 -19
- data/spec/acceptance/attribute_aliases_spec.rb +0 -45
- data/spec/acceptance/attribute_existing_on_object_spec.rb +0 -68
- data/spec/acceptance/attributes_for_spec.rb +0 -97
- data/spec/acceptance/attributes_from_instance_spec.rb +0 -53
- data/spec/acceptance/attributes_ordered_spec.rb +0 -51
- data/spec/acceptance/build_list_spec.rb +0 -56
- data/spec/acceptance/build_spec.rb +0 -86
- data/spec/acceptance/build_stubbed_spec.rb +0 -161
- data/spec/acceptance/callbacks_spec.rb +0 -253
- data/spec/acceptance/create_list_spec.rb +0 -97
- data/spec/acceptance/create_pair_spec.rb +0 -32
- data/spec/acceptance/create_spec.rb +0 -116
- data/spec/acceptance/define_child_before_parent_spec.rb +0 -21
- data/spec/acceptance/defining_methods_inside_a_factory_spec.rb +0 -17
- data/spec/acceptance/definition_camel_string_spec.rb +0 -15
- data/spec/acceptance/definition_spec.rb +0 -21
- data/spec/acceptance/definition_without_block_spec.rb +0 -15
- data/spec/acceptance/global_initialize_with_spec.rb +0 -82
- data/spec/acceptance/global_to_create_spec.rb +0 -122
- data/spec/acceptance/initialize_with_spec.rb +0 -217
- data/spec/acceptance/keyed_by_class_spec.rb +0 -22
- data/spec/acceptance/lint_spec.rb +0 -65
- data/spec/acceptance/modify_factories_spec.rb +0 -184
- data/spec/acceptance/modify_inherited_spec.rb +0 -52
- data/spec/acceptance/nested_attributes_spec.rb +0 -32
- data/spec/acceptance/overrides_spec.rb +0 -61
- data/spec/acceptance/parent_spec.rb +0 -90
- data/spec/acceptance/private_attributes_spec.rb +0 -20
- data/spec/acceptance/register_strategies_spec.rb +0 -136
- data/spec/acceptance/sequence_context_spec.rb +0 -52
- data/spec/acceptance/sequence_spec.rb +0 -61
- data/spec/acceptance/skip_create_spec.rb +0 -19
- data/spec/acceptance/stub_spec.rb +0 -62
- data/spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb +0 -51
- data/spec/acceptance/traits_spec.rb +0 -727
- data/spec/acceptance/transient_attributes_spec.rb +0 -151
- data/spec/factory_girl/aliases_spec.rb +0 -31
- data/spec/factory_girl/attribute/association_spec.rb +0 -28
- data/spec/factory_girl/attribute/dynamic_spec.rb +0 -52
- data/spec/factory_girl/attribute/sequence_spec.rb +0 -16
- data/spec/factory_girl/attribute/static_spec.rb +0 -19
- data/spec/factory_girl/attribute_list_spec.rb +0 -143
- data/spec/factory_girl/attribute_spec.rb +0 -16
- data/spec/factory_girl/callback_spec.rb +0 -41
- data/spec/factory_girl/declaration/implicit_spec.rb +0 -25
- data/spec/factory_girl/declaration_list_spec.rb +0 -67
- data/spec/factory_girl/definition_proxy_spec.rb +0 -215
- data/spec/factory_girl/definition_spec.rb +0 -64
- data/spec/factory_girl/disallows_duplicates_registry_spec.rb +0 -19
- data/spec/factory_girl/evaluator_class_definer_spec.rb +0 -77
- data/spec/factory_girl/factory_spec.rb +0 -259
- data/spec/factory_girl/find_definitions_spec.rb +0 -110
- data/spec/factory_girl/null_factory_spec.rb +0 -13
- data/spec/factory_girl/null_object_spec.rb +0 -22
- data/spec/factory_girl/registry_spec.rb +0 -68
- data/spec/factory_girl/sequence_spec.rb +0 -95
- data/spec/factory_girl/strategy/attributes_for_spec.rb +0 -18
- data/spec/factory_girl/strategy/build_spec.rb +0 -7
- data/spec/factory_girl/strategy/create_spec.rb +0 -25
- data/spec/factory_girl/strategy/stub_spec.rb +0 -38
- data/spec/factory_girl/strategy_calculator_spec.rb +0 -29
- data/spec/factory_girl_spec.rb +0 -22
- data/spec/spec_helper.rb +0 -26
- data/spec/support/macros/define_constant.rb +0 -86
- data/spec/support/matchers/callback.rb +0 -9
- data/spec/support/matchers/declaration.rb +0 -83
- data/spec/support/matchers/delegate.rb +0 -44
- data/spec/support/matchers/trait.rb +0 -11
- data/spec/support/shared_examples/strategy.rb +0 -90
@@ -1,77 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe FactoryGirl::EvaluatorClassDefiner do
|
4
|
-
it "returns an evaluator when accessing the evaluator class" do
|
5
|
-
evaluator = define_evaluator(parent_class: FactoryGirl::Evaluator)
|
6
|
-
|
7
|
-
expect(evaluator).to be_a(FactoryGirl::Evaluator)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "adds each attribute to the evaluator" do
|
11
|
-
attribute = stub_attribute(:attribute) { 1 }
|
12
|
-
evaluator = define_evaluator(attributes: [attribute])
|
13
|
-
|
14
|
-
expect(evaluator.attribute).to eq 1
|
15
|
-
end
|
16
|
-
|
17
|
-
it "evaluates the block in the context of the evaluator" do
|
18
|
-
dependency_attribute = stub("dependency", name: :dependency, to_proc: -> { 1 })
|
19
|
-
dependency_attribute = stub_attribute(:dependency) { 1 }
|
20
|
-
attribute = stub_attribute(:attribute) { dependency + 1 }
|
21
|
-
evaluator = define_evaluator(attributes: [dependency_attribute, attribute])
|
22
|
-
|
23
|
-
expect(evaluator.attribute).to eq 2
|
24
|
-
end
|
25
|
-
|
26
|
-
it "only instance_execs the block once even when returning nil" do
|
27
|
-
count = 0
|
28
|
-
attribute = stub_attribute :attribute do
|
29
|
-
count += 1
|
30
|
-
nil
|
31
|
-
end
|
32
|
-
evaluator = define_evaluator(attributes: [attribute])
|
33
|
-
|
34
|
-
2.times { evaluator.attribute }
|
35
|
-
|
36
|
-
expect(count).to eq 1
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets attributes on the evaluator class" do
|
40
|
-
attributes = [stub_attribute, stub_attribute]
|
41
|
-
evaluator = define_evaluator(attributes: attributes)
|
42
|
-
|
43
|
-
expect(evaluator.attribute_lists).to eq [attributes]
|
44
|
-
end
|
45
|
-
|
46
|
-
context "with a custom evaluator as a parent class" do
|
47
|
-
it "bases its attribute lists on itself and its parent evaluator" do
|
48
|
-
parent_attributes = [stub_attribute, stub_attribute]
|
49
|
-
parent_evaluator_class = define_evaluator_class(attributes: parent_attributes)
|
50
|
-
child_attributes = [stub_attribute, stub_attribute]
|
51
|
-
child_evaluator = define_evaluator(
|
52
|
-
attributes: child_attributes,
|
53
|
-
parent_class: parent_evaluator_class
|
54
|
-
)
|
55
|
-
|
56
|
-
expect(child_evaluator.attribute_lists).to eq [parent_attributes, child_attributes]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def define_evaluator(arguments = {})
|
61
|
-
evaluator_class = define_evaluator_class(arguments)
|
62
|
-
evaluator_class.new(FactoryGirl::Strategy::Null)
|
63
|
-
end
|
64
|
-
|
65
|
-
def define_evaluator_class(arguments = {})
|
66
|
-
evaluator_class_definer = FactoryGirl::EvaluatorClassDefiner.new(
|
67
|
-
arguments[:attributes] || [],
|
68
|
-
arguments[:parent_class] || FactoryGirl::Evaluator
|
69
|
-
)
|
70
|
-
evaluator_class_definer.evaluator_class
|
71
|
-
end
|
72
|
-
|
73
|
-
def stub_attribute(name = :attribute, &value)
|
74
|
-
value ||= -> {}
|
75
|
-
stub(name.to_s, name: name.to_sym, to_proc: value)
|
76
|
-
end
|
77
|
-
end
|
@@ -1,259 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FactoryGirl::Factory do
|
4
|
-
before do
|
5
|
-
@name = :user
|
6
|
-
@class = define_class('User')
|
7
|
-
@factory = FactoryGirl::Factory.new(@name)
|
8
|
-
FactoryGirl.register_factory(@factory)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "has a factory name" do
|
12
|
-
expect(@factory.name).to eq @name
|
13
|
-
end
|
14
|
-
|
15
|
-
it "has a build class" do
|
16
|
-
expect(@factory.build_class).to eq @class
|
17
|
-
end
|
18
|
-
|
19
|
-
it "passes a custom creation block" do
|
20
|
-
strategy = stub("strategy", result: nil, add_observer: true)
|
21
|
-
FactoryGirl::Strategy::Build.stubs(new: strategy)
|
22
|
-
block = -> {}
|
23
|
-
factory = FactoryGirl::Factory.new(:object)
|
24
|
-
factory.to_create(&block)
|
25
|
-
|
26
|
-
factory.run(FactoryGirl::Strategy::Build, {})
|
27
|
-
|
28
|
-
expect(strategy).to have_received(:result).with(instance_of(FactoryGirl::Evaluation))
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns associations" do
|
32
|
-
factory = FactoryGirl::Factory.new(:post)
|
33
|
-
FactoryGirl.register_factory(FactoryGirl::Factory.new(:admin))
|
34
|
-
factory.declare_attribute(FactoryGirl::Declaration::Association.new(:author, {}))
|
35
|
-
factory.declare_attribute(FactoryGirl::Declaration::Association.new(:editor, {}))
|
36
|
-
factory.declare_attribute(FactoryGirl::Declaration::Implicit.new(:admin, factory))
|
37
|
-
factory.associations.each do |association|
|
38
|
-
expect(association).to be_association
|
39
|
-
end
|
40
|
-
expect(factory.associations.to_a.length).to eq 3
|
41
|
-
end
|
42
|
-
|
43
|
-
it "includes associations from the parent factory" do
|
44
|
-
association_on_parent = FactoryGirl::Declaration::Association.new(:association_on_parent, {})
|
45
|
-
association_on_child = FactoryGirl::Declaration::Association.new(:association_on_child, {})
|
46
|
-
|
47
|
-
factory = FactoryGirl::Factory.new(:post)
|
48
|
-
factory.declare_attribute(association_on_parent)
|
49
|
-
FactoryGirl.register_factory(factory)
|
50
|
-
|
51
|
-
child_factory = FactoryGirl::Factory.new(:child_post, parent: :post)
|
52
|
-
child_factory.declare_attribute(association_on_child)
|
53
|
-
|
54
|
-
expect(child_factory.associations.map(&:name)).to eq [:association_on_parent, :association_on_child]
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "when overriding generated attributes with a hash" do
|
58
|
-
before do
|
59
|
-
@name = :name
|
60
|
-
@value = 'The price is right!'
|
61
|
-
@hash = { @name => @value }
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns the overridden value in the generated attributes" do
|
65
|
-
declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!')
|
66
|
-
@factory.declare_attribute(declaration)
|
67
|
-
result = @factory.run(FactoryGirl::Strategy::AttributesFor, @hash)
|
68
|
-
expect(result[@name]).to eq @value
|
69
|
-
end
|
70
|
-
|
71
|
-
it "does not call a lazy attribute block for an overridden attribute" do
|
72
|
-
declaration = FactoryGirl::Declaration::Dynamic.new(@name, false, -> { flunk })
|
73
|
-
@factory.declare_attribute(declaration)
|
74
|
-
@factory.run(FactoryGirl::Strategy::AttributesFor, @hash)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "overrides a symbol parameter with a string parameter" do
|
78
|
-
declaration = FactoryGirl::Declaration::Static.new(@name, 'The price is wrong, Bob!')
|
79
|
-
@factory.declare_attribute(declaration)
|
80
|
-
@hash = { @name.to_s => @value }
|
81
|
-
result = @factory.run(FactoryGirl::Strategy::AttributesFor, @hash)
|
82
|
-
expect(result[@name]).to eq @value
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "overriding an attribute with an alias" do
|
87
|
-
before do
|
88
|
-
@factory.declare_attribute(FactoryGirl::Declaration::Static.new(:test, 'original'))
|
89
|
-
FactoryGirl.aliases << [/(.*)_alias/, '\1']
|
90
|
-
@result = @factory.run(FactoryGirl::Strategy::AttributesFor,
|
91
|
-
test_alias: 'new')
|
92
|
-
end
|
93
|
-
|
94
|
-
it "uses the passed in value for the alias" do
|
95
|
-
expect(@result[:test_alias]).to eq 'new'
|
96
|
-
end
|
97
|
-
|
98
|
-
it "discards the predefined value for the attribute" do
|
99
|
-
expect(@result[:test]).to be_nil
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it "guesses the build class from the factory name" do
|
104
|
-
expect(@factory.build_class).to eq User
|
105
|
-
end
|
106
|
-
|
107
|
-
it "creates a new factory using the class of the parent" do
|
108
|
-
child = FactoryGirl::Factory.new(:child, parent: @factory.name)
|
109
|
-
child.compile
|
110
|
-
expect(child.build_class).to eq @factory.build_class
|
111
|
-
end
|
112
|
-
|
113
|
-
it "creates a new factory while overriding the parent class" do
|
114
|
-
child = FactoryGirl::Factory.new(:child, class: String, parent: @factory.name)
|
115
|
-
child.compile
|
116
|
-
expect(child.build_class).to eq String
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe FactoryGirl::Factory, "when defined with a custom class" do
|
121
|
-
subject { FactoryGirl::Factory.new(:author, class: Float) }
|
122
|
-
its(:build_class) { should eq Float }
|
123
|
-
end
|
124
|
-
|
125
|
-
describe FactoryGirl::Factory, "when given a class that overrides #to_s" do
|
126
|
-
let(:overriding_class) { Overriding::Class }
|
127
|
-
|
128
|
-
before do
|
129
|
-
define_class("Overriding")
|
130
|
-
define_class("Overriding::Class") do
|
131
|
-
def self.to_s
|
132
|
-
"Overriding"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
subject { FactoryGirl::Factory.new(:overriding_class, class: Overriding::Class) }
|
138
|
-
|
139
|
-
it "sets build_class correctly" do
|
140
|
-
expect(subject.build_class).to eq overriding_class
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe FactoryGirl::Factory, "when defined with a class instead of a name" do
|
145
|
-
let(:factory_class) { ArgumentError }
|
146
|
-
let(:name) { :argument_error }
|
147
|
-
|
148
|
-
subject { FactoryGirl::Factory.new(factory_class) }
|
149
|
-
|
150
|
-
its(:name) { should eq name }
|
151
|
-
its(:build_class) { should eq factory_class }
|
152
|
-
end
|
153
|
-
|
154
|
-
describe FactoryGirl::Factory, "when defined with a custom class name" do
|
155
|
-
subject { FactoryGirl::Factory.new(:author, class: :argument_error) }
|
156
|
-
its(:build_class) { should eq ArgumentError }
|
157
|
-
end
|
158
|
-
|
159
|
-
describe FactoryGirl::Factory, "with a name ending in s" do
|
160
|
-
let(:name) { :business }
|
161
|
-
let(:business_class) { Business }
|
162
|
-
|
163
|
-
before { define_class('Business') }
|
164
|
-
subject { FactoryGirl::Factory.new(name) }
|
165
|
-
|
166
|
-
its(:name) { should eq name }
|
167
|
-
its(:build_class) { should eq business_class }
|
168
|
-
end
|
169
|
-
|
170
|
-
describe FactoryGirl::Factory, "with a string for a name" do
|
171
|
-
let(:name) { :string }
|
172
|
-
subject { FactoryGirl::Factory.new(name.to_s) }
|
173
|
-
its(:name) { should eq name }
|
174
|
-
end
|
175
|
-
|
176
|
-
describe FactoryGirl::Factory, "for namespaced class" do
|
177
|
-
let(:name) { :settings }
|
178
|
-
let(:settings_class) { Admin::Settings }
|
179
|
-
|
180
|
-
before do
|
181
|
-
define_class("Admin")
|
182
|
-
define_class("Admin::Settings")
|
183
|
-
end
|
184
|
-
|
185
|
-
context "with a namespaced class with Namespace::Class syntax" do
|
186
|
-
subject { FactoryGirl::Factory.new(name, class: "Admin::Settings") }
|
187
|
-
|
188
|
-
it "sets build_class correctly" do
|
189
|
-
expect(subject.build_class).to eq settings_class
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "with a namespaced class with namespace/class syntax" do
|
194
|
-
subject { FactoryGirl::Factory.new(name, class: "admin/settings") }
|
195
|
-
|
196
|
-
it "sets build_class correctly" do
|
197
|
-
expect(subject.build_class).to eq settings_class
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe FactoryGirl::Factory, "human names" do
|
203
|
-
context "factory name without underscores" do
|
204
|
-
subject { FactoryGirl::Factory.new(:user) }
|
205
|
-
its(:names) { should eq [:user] }
|
206
|
-
its(:human_names) { should eq ["user"] }
|
207
|
-
end
|
208
|
-
|
209
|
-
context "factory name with underscores" do
|
210
|
-
subject { FactoryGirl::Factory.new(:happy_user) }
|
211
|
-
its(:names) { should eq [:happy_user] }
|
212
|
-
its(:human_names) { should eq ["happy user"] }
|
213
|
-
end
|
214
|
-
|
215
|
-
context "factory name with big letters" do
|
216
|
-
subject { FactoryGirl::Factory.new(:LoL) }
|
217
|
-
its(:names) { should eq [:LoL] }
|
218
|
-
its(:human_names) { should eq ["lol"] }
|
219
|
-
end
|
220
|
-
|
221
|
-
context "factory name with aliases" do
|
222
|
-
subject { FactoryGirl::Factory.new(:happy_user, aliases: [:gleeful_user, :person]) }
|
223
|
-
its(:names) { should eq [:happy_user, :gleeful_user, :person] }
|
224
|
-
its(:human_names) { should eq ["happy user", "gleeful user", "person"] }
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe FactoryGirl::Factory, "running a factory" do
|
229
|
-
subject { FactoryGirl::Factory.new(:user) }
|
230
|
-
let(:attribute) { FactoryGirl::Attribute::Static.new(:name, "value", false) }
|
231
|
-
let(:declaration) { FactoryGirl::Declaration::Static.new(:name, "value", false) }
|
232
|
-
let(:strategy) { stub("strategy", result: "result", add_observer: true) }
|
233
|
-
let(:attributes) { [attribute] }
|
234
|
-
let(:attribute_list) { stub('attribute-list', declarations: [declaration], to_a: attributes) }
|
235
|
-
|
236
|
-
before do
|
237
|
-
define_model("User", name: :string)
|
238
|
-
FactoryGirl::Declaration::Static.stubs(new: declaration)
|
239
|
-
declaration.stubs(to_attributes: attributes)
|
240
|
-
FactoryGirl::Strategy::Build.stubs(new: strategy)
|
241
|
-
subject.declare_attribute(declaration)
|
242
|
-
end
|
243
|
-
|
244
|
-
it "creates the right strategy using the build class when running" do
|
245
|
-
subject.run(FactoryGirl::Strategy::Build, {})
|
246
|
-
expect(FactoryGirl::Strategy::Build).to have_received(:new).once
|
247
|
-
end
|
248
|
-
|
249
|
-
it "returns the result from the strategy when running" do
|
250
|
-
expect(subject.run(FactoryGirl::Strategy::Build, {})).to eq "result"
|
251
|
-
end
|
252
|
-
|
253
|
-
it "calls the block and returns the result" do
|
254
|
-
block_run = nil
|
255
|
-
block = ->(result) { block_run = "changed" }
|
256
|
-
subject.run(FactoryGirl::Strategy::Build, { }, &block)
|
257
|
-
expect(block_run).to eq "changed"
|
258
|
-
end
|
259
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
share_examples_for "finds definitions" do
|
4
|
-
before do
|
5
|
-
FactoryGirl.stubs(:load)
|
6
|
-
FactoryGirl.find_definitions
|
7
|
-
end
|
8
|
-
|
9
|
-
subject { FactoryGirl }
|
10
|
-
end
|
11
|
-
|
12
|
-
RSpec::Matchers.define :load_definitions_from do |file|
|
13
|
-
match do |given|
|
14
|
-
@has_received = have_received(:load).with(File.expand_path(file))
|
15
|
-
@has_received.matches?(given)
|
16
|
-
end
|
17
|
-
|
18
|
-
description do
|
19
|
-
"load definitions from #{file}"
|
20
|
-
end
|
21
|
-
|
22
|
-
failure_message_for_should do
|
23
|
-
@has_received.failure_message
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "definition loading" do
|
28
|
-
def self.in_directory_with_files(*files)
|
29
|
-
before do
|
30
|
-
@pwd = Dir.pwd
|
31
|
-
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
32
|
-
FileUtils.mkdir_p @tmp_dir
|
33
|
-
Dir.chdir(@tmp_dir)
|
34
|
-
|
35
|
-
files.each do |file|
|
36
|
-
FileUtils.mkdir_p File.dirname(file)
|
37
|
-
FileUtils.touch file
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
after do
|
42
|
-
Dir.chdir(@pwd)
|
43
|
-
FileUtils.rm_rf(@tmp_dir)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "with factories.rb" do
|
48
|
-
in_directory_with_files 'factories.rb'
|
49
|
-
it_should_behave_like "finds definitions" do
|
50
|
-
it { should load_definitions_from('factories.rb') }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
%w(spec test).each do |dir|
|
55
|
-
describe "with a factories file under #{dir}" do
|
56
|
-
in_directory_with_files File.join(dir, 'factories.rb')
|
57
|
-
it_should_behave_like "finds definitions" do
|
58
|
-
it { should load_definitions_from("#{dir}/factories.rb") }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "with a factories file under #{dir}/factories" do
|
63
|
-
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb')
|
64
|
-
it_should_behave_like "finds definitions" do
|
65
|
-
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "with several factories files under #{dir}/factories" do
|
70
|
-
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb'),
|
71
|
-
File.join(dir, 'factories', 'person_factory.rb')
|
72
|
-
it_should_behave_like "finds definitions" do
|
73
|
-
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
74
|
-
it { should load_definitions_from("#{dir}/factories/person_factory.rb") }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "with several factories files under #{dir}/factories in non-alphabetical order" do
|
79
|
-
in_directory_with_files File.join(dir, 'factories', 'b.rb'),
|
80
|
-
File.join(dir, 'factories', 'a.rb')
|
81
|
-
it "loads the files in the right order" do
|
82
|
-
FactoryGirl.stubs(:load)
|
83
|
-
sorted_load_order = sequence("load order")
|
84
|
-
FactoryGirl.expects(:load).with(includes("a.rb")).in_sequence(sorted_load_order)
|
85
|
-
FactoryGirl.expects(:load).with(includes("b.rb")).in_sequence(sorted_load_order)
|
86
|
-
FactoryGirl.find_definitions
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "with nested and unnested factories files under #{dir}" do
|
91
|
-
in_directory_with_files File.join(dir, 'factories.rb'),
|
92
|
-
File.join(dir, 'factories', 'post_factory.rb'),
|
93
|
-
File.join(dir, 'factories', 'person_factory.rb')
|
94
|
-
it_should_behave_like "finds definitions" do
|
95
|
-
it { should load_definitions_from("#{dir}/factories.rb") }
|
96
|
-
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
97
|
-
it { should load_definitions_from("#{dir}/factories/person_factory.rb") }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "with deeply nested factory files under #{dir}" do
|
102
|
-
in_directory_with_files File.join(dir, 'factories', 'subdirectory', 'post_factory.rb'),
|
103
|
-
File.join(dir, 'factories', 'subdirectory', 'person_factory.rb')
|
104
|
-
it_should_behave_like "finds definitions" do
|
105
|
-
it { should load_definitions_from("#{dir}/factories/subdirectory/post_factory.rb") }
|
106
|
-
it { should load_definitions_from("#{dir}/factories/subdirectory/person_factory.rb") }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe FactoryGirl::NullFactory do
|
4
|
-
it { should delegate(:defined_traits).to(:definition) }
|
5
|
-
it { should delegate(:callbacks).to(:definition) }
|
6
|
-
it { should delegate(:attributes).to(:definition) }
|
7
|
-
it { should delegate(:constructor).to(:definition) }
|
8
|
-
|
9
|
-
its(:compile) { should be_nil }
|
10
|
-
its(:class_name) { should be_nil }
|
11
|
-
its(:attributes) { should be_an_instance_of(FactoryGirl::AttributeList) }
|
12
|
-
its(:evaluator_class) { should eq FactoryGirl::Evaluator }
|
13
|
-
end
|