factory_girl 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- factory_girl (3.1.0)
4
+ factory_girl (3.1.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.1.0)
4
+ factory_girl (3.1.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.1.0)
4
+ factory_girl (3.1.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/joshuaclayton/dev/gems/factory_girl
3
3
  specs:
4
- factory_girl (3.1.0)
4
+ factory_girl (3.1.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -3,16 +3,22 @@ require "active_support/core_ext/module/delegation"
3
3
  require 'factory_girl/errors'
4
4
  require 'factory_girl/factory_runner'
5
5
  require 'factory_girl/strategy_calculator'
6
- require 'factory_girl/strategy'
6
+ require "factory_girl/strategy/build"
7
+ require "factory_girl/strategy/create"
8
+ require "factory_girl/strategy/attributes_for"
9
+ require "factory_girl/strategy/stub"
10
+ require "factory_girl/strategy/null"
7
11
  require 'factory_girl/registry'
8
12
  require 'factory_girl/null_factory'
9
13
  require 'factory_girl/null_object'
14
+ require 'factory_girl/evaluation'
10
15
  require 'factory_girl/factory'
11
16
  require 'factory_girl/attribute_assigner'
12
17
  require 'factory_girl/evaluator'
13
18
  require 'factory_girl/evaluator_class_definer'
14
19
  require 'factory_girl/attribute'
15
20
  require 'factory_girl/callback'
21
+ require 'factory_girl/callback_runner'
16
22
  require 'factory_girl/declaration_list'
17
23
  require 'factory_girl/declaration'
18
24
  require 'factory_girl/sequence'
@@ -0,0 +1,20 @@
1
+ module FactoryGirl
2
+ class CallbackRunner
3
+ def initialize(callbacks, evaluator)
4
+ @callbacks = callbacks
5
+ @evaluator = evaluator
6
+ end
7
+
8
+ def update(name, result_instance)
9
+ callbacks_by_name(name).each do |callback|
10
+ callback.run(result_instance, @evaluator)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def callbacks_by_name(name)
17
+ @callbacks.select {|callback| callback.name == name }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ require "observer"
2
+
3
+ module FactoryGirl
4
+ class Evaluation
5
+ include Observable
6
+
7
+ def initialize(attribute_assigner, to_create)
8
+ @attribute_assigner = attribute_assigner
9
+ @to_create = to_create
10
+ end
11
+
12
+ def create(result_instance)
13
+ @to_create[result_instance]
14
+ end
15
+
16
+ delegate :object, :hash, to: :@attribute_assigner
17
+
18
+ def notify(name, result_instance)
19
+ changed
20
+ notify_observers(name, result_instance)
21
+ end
22
+ end
23
+ end
@@ -3,7 +3,7 @@ require "active_support/core_ext/class/attribute"
3
3
 
4
4
  module FactoryGirl
5
5
  class Evaluator
6
- class_attribute :callbacks, :attribute_lists
6
+ class_attribute :attribute_lists
7
7
 
8
8
  def self.attribute_list
9
9
  AttributeList.new.tap do |list|
@@ -25,8 +25,6 @@ module FactoryGirl
25
25
  @overrides.each do |name, value|
26
26
  singleton_class.send :define_method, name, lambda { value }
27
27
  end
28
-
29
- @build_strategy.add_observer(CallbackRunner.new(self.class.callbacks, self))
30
28
  end
31
29
 
32
30
  def association(factory_name, overrides = {})
@@ -56,20 +54,5 @@ module FactoryGirl
56
54
  def __overrides
57
55
  @overrides
58
56
  end
59
-
60
- private
61
-
62
- class CallbackRunner
63
- def initialize(callbacks, evaluator)
64
- @callbacks = callbacks
65
- @evaluator = evaluator
66
- end
67
-
68
- def update(name, result_instance)
69
- @callbacks.select {|callback| callback.name == name }.each do |callback|
70
- callback.run(result_instance, @evaluator)
71
- end
72
- end
73
- end
74
57
  end
75
58
  end
@@ -1,8 +1,7 @@
1
1
  module FactoryGirl
2
2
  class EvaluatorClassDefiner
3
- def initialize(attributes, callbacks, parent_class)
3
+ def initialize(attributes, parent_class)
4
4
  @parent_class = parent_class
5
- @callbacks = callbacks
6
5
  @attributes = attributes
7
6
 
8
7
  attributes.each do |attribute|
@@ -12,8 +11,6 @@ module FactoryGirl
12
11
 
13
12
  def evaluator_class
14
13
  @evaluator_class ||= Class.new(@parent_class).tap do |klass|
15
- klass.callbacks ||= []
16
- klass.callbacks += @callbacks
17
14
  klass.attribute_lists ||= []
18
15
  klass.attribute_lists += [@attributes]
19
16
  end
@@ -35,7 +35,10 @@ module FactoryGirl
35
35
  evaluator = evaluator_class.new(strategy, overrides.symbolize_keys)
36
36
  attribute_assigner = AttributeAssigner.new(evaluator, &instance_builder)
37
37
 
38
- strategy.result(attribute_assigner, to_create).tap(&block)
38
+ evaluation = Evaluation.new(attribute_assigner, to_create)
39
+ evaluation.add_observer(CallbackRunner.new(callbacks, evaluator))
40
+
41
+ strategy.result(evaluation).tap(&block)
39
42
  end
40
43
 
41
44
  def human_names
@@ -97,7 +100,7 @@ module FactoryGirl
97
100
  end
98
101
 
99
102
  def evaluator_class
100
- @evaluator_class ||= EvaluatorClassDefiner.new(attributes, callbacks, parent.evaluator_class).evaluator_class
103
+ @evaluator_class ||= EvaluatorClassDefiner.new(attributes, parent.evaluator_class).evaluator_class
101
104
  end
102
105
 
103
106
  def attributes
@@ -110,7 +113,7 @@ module FactoryGirl
110
113
  end
111
114
 
112
115
  def callbacks
113
- processing_order.map {|factory| factory.callbacks }.flatten
116
+ parent.callbacks + processing_order.map {|factory| factory.callbacks }.flatten
114
117
  end
115
118
 
116
119
  def constructor
@@ -1,12 +1,12 @@
1
1
  module FactoryGirl
2
- class Strategy #:nodoc:
3
- class AttributesFor < Strategy #:nodoc:
2
+ module Strategy
3
+ class AttributesFor
4
4
  def association(runner)
5
5
  runner.run(Strategy::Null)
6
6
  end
7
7
 
8
- def result(attribute_assigner, to_create)
9
- attribute_assigner.hash
8
+ def result(evaluation)
9
+ evaluation.hash
10
10
  end
11
11
  end
12
12
  end
@@ -1,13 +1,13 @@
1
1
  module FactoryGirl
2
- class Strategy #:nodoc:
3
- class Build < Strategy #:nodoc:
2
+ module Strategy
3
+ class Build
4
4
  def association(runner)
5
5
  runner.run
6
6
  end
7
7
 
8
- def result(attribute_assigner, to_create)
9
- attribute_assigner.object.tap do |result_instance|
10
- run_callbacks(:after_build, result_instance)
8
+ def result(evaluation)
9
+ evaluation.object.tap do |instance|
10
+ evaluation.notify(:after_build, instance)
11
11
  end
12
12
  end
13
13
  end
@@ -1,16 +1,16 @@
1
1
  module FactoryGirl
2
- class Strategy #:nodoc:
3
- class Create < Strategy #:nodoc:
2
+ module Strategy
3
+ class Create
4
4
  def association(runner)
5
5
  runner.run
6
6
  end
7
7
 
8
- def result(attribute_assigner, to_create)
9
- attribute_assigner.object.tap do |result_instance|
10
- run_callbacks(:after_build, result_instance)
11
- run_callbacks(:before_create, result_instance)
12
- to_create[result_instance]
13
- run_callbacks(:after_create, result_instance)
8
+ def result(evaluation)
9
+ evaluation.object.tap do |instance|
10
+ evaluation.notify(:after_build, instance)
11
+ evaluation.notify(:before_create, instance)
12
+ evaluation.create(instance)
13
+ evaluation.notify(:after_create, instance)
14
14
  end
15
15
  end
16
16
  end
@@ -1,10 +1,10 @@
1
1
  module FactoryGirl
2
- class Strategy
2
+ module Strategy
3
3
  class Null
4
4
  def association(runner)
5
5
  end
6
6
 
7
- def result(attribute_assigner, to_create)
7
+ def result(evaluation)
8
8
  end
9
9
  end
10
10
  end
@@ -1,16 +1,16 @@
1
1
  module FactoryGirl
2
- class Strategy
3
- class Stub < Strategy #:nodoc:
2
+ module Strategy
3
+ class Stub
4
4
  @@next_id = 1000
5
5
 
6
6
  def association(runner)
7
7
  runner.run(Strategy::Stub)
8
8
  end
9
9
 
10
- def result(attribute_assigner, to_create)
11
- attribute_assigner.object.tap do |result_instance|
12
- stub_database_interaction_on_result(result_instance)
13
- run_callbacks(:after_stub, result_instance)
10
+ def result(evaluation)
11
+ evaluation.object.tap do |instance|
12
+ stub_database_interaction_on_result(instance)
13
+ evaluation.notify(:after_stub, instance)
14
14
  end
15
15
  end
16
16
 
@@ -15,7 +15,7 @@ module FactoryGirl
15
15
  private
16
16
 
17
17
  def strategy_is_object?
18
- @name_or_object.is_a?(Class) && @name_or_object.ancestors.include?(::FactoryGirl::Strategy)
18
+ @name_or_object.is_a?(Class)
19
19
  end
20
20
 
21
21
  def strategy_name_to_object
@@ -1,4 +1,4 @@
1
1
  module FactoryGirl
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
4
4
 
@@ -5,22 +5,28 @@ describe "a generated attributes hash" do
5
5
 
6
6
  before do
7
7
  define_model('User')
8
+ define_model('Comment')
8
9
 
9
10
  define_model('Post', title: :string,
10
11
  body: :string,
11
12
  summary: :string,
12
13
  user_id: :integer) do
13
14
  belongs_to :user
15
+ has_many :comments
14
16
  end
15
17
 
16
18
  FactoryGirl.define do
17
19
  factory :user
20
+ factory :comment
18
21
 
19
22
  factory :post do
20
23
  title { "default title" }
21
24
  body { "default body" }
22
25
  summary { title }
23
26
  user
27
+ comments do |c|
28
+ [c.association(:comment)]
29
+ end
24
30
  end
25
31
  end
26
32
  end
@@ -4,10 +4,9 @@ describe FactoryGirl::EvaluatorClassDefiner do
4
4
  let(:simple_attribute) { stub("simple attribute", name: :simple, to_proc: lambda { 1 }) }
5
5
  let(:relative_attribute) { stub("relative attribute", name: :relative, to_proc: lambda { simple + 1 }) }
6
6
  let(:attribute_that_raises_a_second_time) { stub("attribute that would raise without a cache", name: :raises_without_proper_cache, to_proc: lambda { raise "failed" if @run; @run = true; nil }) }
7
- let(:callbacks) { [stub("callback 1"), stub("callback 2")] }
8
7
 
9
8
  let(:attributes) { [simple_attribute, relative_attribute, attribute_that_raises_a_second_time] }
10
- let(:class_definer) { FactoryGirl::EvaluatorClassDefiner.new(attributes, callbacks, FactoryGirl::Evaluator) }
9
+ let(:class_definer) { FactoryGirl::EvaluatorClassDefiner.new(attributes, FactoryGirl::Evaluator) }
11
10
  let(:evaluator) { class_definer.evaluator_class.new(stub("build strategy", add_observer: true)) }
12
11
 
13
12
  it "returns an evaluator when accessing the evaluator class" do
@@ -32,23 +31,14 @@ describe FactoryGirl::EvaluatorClassDefiner do
32
31
  class_definer.evaluator_class.attribute_lists.should == [attributes]
33
32
  end
34
33
 
35
- it "sets callbacks on the evaluator class" do
36
- class_definer.evaluator_class.callbacks.should == callbacks
37
- end
38
-
39
34
  context "with a custom evaluator as a parent class" do
40
- let(:child_callbacks) { [stub("child callback 1"), stub("child callback 2")] }
41
35
  let(:child_attributes) { [stub("child attribute", name: :simple, to_proc: lambda { 1 })] }
42
- let(:child_definer) { FactoryGirl::EvaluatorClassDefiner.new(child_attributes, child_callbacks, class_definer.evaluator_class) }
36
+ let(:child_definer) { FactoryGirl::EvaluatorClassDefiner.new(child_attributes, class_definer.evaluator_class) }
43
37
 
44
38
  subject { child_definer.evaluator_class }
45
39
 
46
40
  it "bases its attribute lists on itself and its parent evaluator" do
47
41
  subject.attribute_lists.should == [attributes, child_attributes]
48
42
  end
49
-
50
- it "bases its callbacks on itself and its parent evaluator" do
51
- subject.callbacks.should == callbacks + child_callbacks
52
- end
53
43
  end
54
44
  end
@@ -25,7 +25,7 @@ describe FactoryGirl::Factory do
25
25
 
26
26
  factory.run(FactoryGirl::Strategy::Build, {})
27
27
 
28
- strategy.should have_received(:result).with(instance_of(FactoryGirl::AttributeAssigner), block)
28
+ strategy.should have_received(:result).with(instance_of(FactoryGirl::Evaluation))
29
29
  end
30
30
 
31
31
  it "returns associations" do
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FactoryGirl::Strategy::AttributesFor do
4
- let(:result) { { name: "John Doe", gender: "Male", admin: false } }
5
- let(:attribute_assigner) { stub("attribute assigner", hash: result) }
4
+ let(:result) { { name: "John Doe", gender: "Male", admin: false } }
5
+ let(:evaluation) { stub("evaluation", hash: result) }
6
6
 
7
7
  it_should_behave_like "strategy without association support"
8
8
 
9
- it "returns the hash from the attribute assigner" do
10
- subject.result(attribute_assigner, lambda {|item| item }).should == result
9
+ it "returns the hash from the evaluation" do
10
+ subject.result(evaluation).should == result
11
11
  end
12
12
 
13
13
  it "does not run the to_create block" do
14
14
  expect do
15
- subject.result(attribute_assigner, lambda {|item| raise "failed" })
15
+ subject.result(evaluation)
16
16
  end.to_not raise_error
17
17
  end
18
18
  end
@@ -5,9 +5,21 @@ describe FactoryGirl::Strategy::Create do
5
5
  it_should_behave_like "strategy with callbacks", :after_build, :before_create, :after_create
6
6
 
7
7
  it "runs a custom create block" do
8
- block_run = false
9
- block = lambda {|instance| block_run = true }
10
- subject.result(stub("assigner", object: stub("result instance")), block)
11
- block_run.should be_true
8
+ evaluation_class = Class.new do
9
+ def initialize
10
+ @block_run = false
11
+ end
12
+
13
+ attr_reader :block_run
14
+
15
+ def create(*instance)
16
+ @block_run = true
17
+ end
18
+ end
19
+
20
+ evaluation = evaluation_class.new
21
+ evaluation.stubs(object: nil, notify: nil)
22
+ subject.result(evaluation)
23
+ evaluation.block_run.should be_true
12
24
  end
13
25
  end
@@ -14,25 +14,24 @@ describe FactoryGirl::Strategy::Stub do
14
14
  end.new
15
15
  end
16
16
 
17
- let(:assigner) { stub("attribute assigner", object: result_instance) }
18
- let(:to_create) { lambda {|instance| instance } }
17
+ let(:evaluation) { stub("evaluation", object: result_instance, notify: true) }
19
18
 
20
- it { subject.result(assigner, to_create).should_not be_new_record }
21
- it { subject.result(assigner, to_create).should be_persisted }
19
+ it { subject.result(evaluation).should_not be_new_record }
20
+ it { subject.result(evaluation).should be_persisted }
22
21
 
23
22
  it "assigns created_at" do
24
- created_at = subject.result(assigner, to_create).created_at
23
+ created_at = subject.result(evaluation).created_at
25
24
  created_at.should == Time.now
26
25
 
27
26
  Timecop.travel(150000)
28
27
 
29
- subject.result(assigner, to_create).created_at.should == created_at
28
+ subject.result(evaluation).created_at.should == created_at
30
29
  end
31
30
 
32
31
  [:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
33
32
  it "raises when attempting to connect to the database by calling #{database_method}" do
34
33
  expect do
35
- subject.result(assigner, to_create).send(database_method)
34
+ subject.result(evaluation).send(database_method)
36
35
  end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database")
37
36
  end
38
37
  end
@@ -8,16 +8,6 @@ describe FactoryGirl::StrategyCalculator, "with a FactoryGirl::Strategy object"
8
8
  end
9
9
  end
10
10
 
11
- describe FactoryGirl::StrategyCalculator, "with a non-FactoryGirl::Strategy object" do
12
- before { define_class "MyAwesomeStrategy" }
13
-
14
- let(:strategy) { MyAwesomeStrategy }
15
-
16
- it "returns the strategy object" do
17
- expect { FactoryGirl::StrategyCalculator.new(strategy).strategy }.to raise_error "unrecognized method MyAwesomeStrategy"
18
- end
19
- end
20
-
21
11
  describe FactoryGirl::StrategyCalculator do
22
12
  it "returns the correct strategy object for :build" do
23
13
  FactoryGirl::StrategyCalculator.new(:build).strategy.should == FactoryGirl::Strategy::Build
@@ -27,7 +27,7 @@ RSpec::Matchers.define :delegate do |delegated_method|
27
27
  end
28
28
  end
29
29
 
30
- failure_message do
30
+ failure_message_for_should do
31
31
  if Class === @instance
32
32
  message = "expected #{@instance.name} "
33
33
  prefix = '.'
@@ -70,36 +70,22 @@ shared_examples_for "strategy with strategy: :build" do |factory_girl_strategy_c
70
70
  end
71
71
 
72
72
  shared_examples_for "strategy with callbacks" do |*callback_names|
73
- let(:callback_observer) do
74
- define_class("CallbackObserver") do
75
- attr_reader :callbacks_called
76
-
77
- def initialize
78
- @callbacks_called = []
79
- end
80
-
81
- def update(callback_name, assigner)
82
- @callbacks_called << [callback_name, assigner]
83
- end
84
- end.new
85
- end
86
-
87
73
  let(:result_instance) do
88
74
  define_class("ResultInstance") do
89
75
  attr_accessor :id
90
76
  end.new
91
77
  end
92
78
 
93
- let(:assigner) { stub("attribute assigner", object: result_instance) }
94
-
95
- before { subject.add_observer(callback_observer) }
79
+ let(:evaluation) { stub("evaluation", object: result_instance, notify: true, create: nil) }
96
80
 
97
- it "runs the callbacks #{callback_names} with the assigner's object" do
98
- subject.result(assigner, lambda {|instance| instance })
99
- callback_observer.callbacks_called.should == callback_names.map {|name| [name, assigner.object] }
81
+ it "runs the callbacks #{callback_names} with the evaluation's object" do
82
+ subject.result(evaluation)
83
+ callback_names.each do |name|
84
+ evaluation.should have_received(:notify).with(name, evaluation.object)
85
+ end
100
86
  end
101
87
 
102
- it "returns the object from the assigner" do
103
- subject.result(assigner, lambda {|instance| instance }).should == assigner.object
88
+ it "returns the object from the evaluation" do
89
+ subject.result(evaluation).should == evaluation.object
104
90
  end
105
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_girl
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-06 00:00:00.000000000 Z
13
+ date: 2012-04-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70215892807040 !ruby/object:Gem::Requirement
17
+ requirement: &70213807643080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70215892807040
25
+ version_requirements: *70213807643080
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70215892806560 !ruby/object:Gem::Requirement
28
+ requirement: &70213807642540 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70215892806560
36
+ version_requirements: *70213807642540
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cucumber
39
- requirement: &70215892806060 !ruby/object:Gem::Requirement
39
+ requirement: &70213807641780 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.1'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70215892806060
47
+ version_requirements: *70213807641780
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: timecop
50
- requirement: &70215892805660 !ruby/object:Gem::Requirement
50
+ requirement: &70213807640520 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70215892805660
58
+ version_requirements: *70213807640520
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: simplecov
61
- requirement: &70215892805160 !ruby/object:Gem::Requirement
61
+ requirement: &70213807654720 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70215892805160
69
+ version_requirements: *70213807654720
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: aruba
72
- requirement: &70215892804720 !ruby/object:Gem::Requirement
72
+ requirement: &70213807653320 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70215892804720
80
+ version_requirements: *70213807653320
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: mocha
83
- requirement: &70215893186120 !ruby/object:Gem::Requirement
83
+ requirement: &70213807651760 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70215893186120
91
+ version_requirements: *70213807651760
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: bourne
94
- requirement: &70215893156440 !ruby/object:Gem::Requirement
94
+ requirement: &70213807650780 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70215893156440
102
+ version_requirements: *70213807650780
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: appraisal
105
- requirement: &70215893134240 !ruby/object:Gem::Requirement
105
+ requirement: &70213807649900 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0.4'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70215893134240
113
+ version_requirements: *70213807649900
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: sqlite3-ruby
116
- requirement: &70215893110760 !ruby/object:Gem::Requirement
116
+ requirement: &70213807649360 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *70215893110760
124
+ version_requirements: *70213807649360
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: yard
127
- requirement: &70215893076860 !ruby/object:Gem::Requirement
127
+ requirement: &70213807648700 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *70215893076860
135
+ version_requirements: *70213807648700
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: bluecloth
138
- requirement: &70215893049900 !ruby/object:Gem::Requirement
138
+ requirement: &70213807740080 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *70215893049900
146
+ version_requirements: *70213807740080
147
147
  description: ! "factory_girl provides a framework and DSL for defining and\n using
148
148
  factories - less error-prone, more explicit, and\n all-around
149
149
  easier to work with than fixtures."
@@ -193,6 +193,7 @@ files:
193
193
  - lib/factory_girl/attribute_assigner.rb
194
194
  - lib/factory_girl/attribute_list.rb
195
195
  - lib/factory_girl/callback.rb
196
+ - lib/factory_girl/callback_runner.rb
196
197
  - lib/factory_girl/declaration.rb
197
198
  - lib/factory_girl/declaration/association.rb
198
199
  - lib/factory_girl/declaration/dynamic.rb
@@ -202,6 +203,7 @@ files:
202
203
  - lib/factory_girl/definition.rb
203
204
  - lib/factory_girl/definition_proxy.rb
204
205
  - lib/factory_girl/errors.rb
206
+ - lib/factory_girl/evaluation.rb
205
207
  - lib/factory_girl/evaluator.rb
206
208
  - lib/factory_girl/evaluator_class_definer.rb
207
209
  - lib/factory_girl/factory.rb
@@ -213,7 +215,6 @@ files:
213
215
  - lib/factory_girl/reload.rb
214
216
  - lib/factory_girl/sequence.rb
215
217
  - lib/factory_girl/step_definitions.rb
216
- - lib/factory_girl/strategy.rb
217
218
  - lib/factory_girl/strategy/attributes_for.rb
218
219
  - lib/factory_girl/strategy/build.rb
219
220
  - lib/factory_girl/strategy/create.rb
@@ -284,7 +285,6 @@ files:
284
285
  - spec/factory_girl/strategy/create_spec.rb
285
286
  - spec/factory_girl/strategy/stub_spec.rb
286
287
  - spec/factory_girl/strategy_calculator_spec.rb
287
- - spec/factory_girl/strategy_spec.rb
288
288
  - spec/factory_girl_spec.rb
289
289
  - spec/spec_helper.rb
290
290
  - spec/support/macros/define_constant.rb
@@ -387,7 +387,6 @@ test_files:
387
387
  - spec/factory_girl/strategy/create_spec.rb
388
388
  - spec/factory_girl/strategy/stub_spec.rb
389
389
  - spec/factory_girl/strategy_calculator_spec.rb
390
- - spec/factory_girl/strategy_spec.rb
391
390
  - spec/factory_girl_spec.rb
392
391
  - spec/spec_helper.rb
393
392
  - spec/support/macros/define_constant.rb
@@ -1,33 +0,0 @@
1
- require "factory_girl/strategy/build"
2
- require "factory_girl/strategy/create"
3
- require "factory_girl/strategy/attributes_for"
4
- require "factory_girl/strategy/stub"
5
- require "factory_girl/strategy/null"
6
- require "observer"
7
-
8
- module FactoryGirl
9
- class Strategy #:nodoc:
10
- include Observable
11
-
12
- def association(runner)
13
- raise NotImplementedError, "Strategies must return an association"
14
- end
15
-
16
- def result(attribute_assigner, to_create)
17
- raise NotImplementedError, "Strategies must return a result"
18
- end
19
-
20
- def self.ensure_strategy_exists!(strategy)
21
- unless Strategy.const_defined? strategy.to_s.camelize
22
- raise ArgumentError, "Unknown strategy: #{strategy}"
23
- end
24
- end
25
-
26
- private
27
-
28
- def run_callbacks(name, result_instance)
29
- changed
30
- notify_observers(name, result_instance)
31
- end
32
- end
33
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FactoryGirl::Strategy do
4
- it "raises an error when asking for the result" do
5
- expect { subject.result(stub("assigner"), lambda {|instance| instance }) }.to raise_error(NotImplementedError, "Strategies must return a result")
6
- end
7
-
8
- it "raises an error when asking for the association" do
9
- expect { subject.association(stub("runner")) }.to raise_error(NotImplementedError, "Strategies must return an association")
10
- end
11
- end
12
-
13
- describe FactoryGirl::Strategy, ".ensure_strategy_exists!" do
14
- it "raises when passed a nonexistent strategy" do
15
- expect { FactoryGirl::Strategy.ensure_strategy_exists!(:nonexistent) }.to raise_error(ArgumentError, "Unknown strategy: nonexistent")
16
- end
17
-
18
- it "doesn't raise when passed a valid strategy" do
19
- expect { FactoryGirl::Strategy.ensure_strategy_exists!(:create) }.to_not raise_error
20
- end
21
- end