factory_girl_kibiz0r 2.0.0.beta2

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 (83) hide show
  1. data/Appraisals +12 -0
  2. data/CONTRIBUTION_GUIDELINES.md +9 -0
  3. data/Changelog +29 -0
  4. data/GETTING_STARTED.md +246 -0
  5. data/Gemfile +12 -0
  6. data/Gemfile.lock +62 -0
  7. data/LICENSE +19 -0
  8. data/README.md +64 -0
  9. data/Rakefile +54 -0
  10. data/features/factory_girl_steps.feature +151 -0
  11. data/features/step_definitions/database_steps.rb +20 -0
  12. data/features/support/env.rb +6 -0
  13. data/features/support/factories.rb +84 -0
  14. data/lib/factory_girl/aliases.rb +21 -0
  15. data/lib/factory_girl/attribute/association.rb +24 -0
  16. data/lib/factory_girl/attribute/callback.rb +16 -0
  17. data/lib/factory_girl/attribute/dynamic.rb +21 -0
  18. data/lib/factory_girl/attribute/implicit.rb +36 -0
  19. data/lib/factory_girl/attribute/list.rb +19 -0
  20. data/lib/factory_girl/attribute/sequence.rb +16 -0
  21. data/lib/factory_girl/attribute/static.rb +18 -0
  22. data/lib/factory_girl/attribute.rb +42 -0
  23. data/lib/factory_girl/definition_proxy.rb +147 -0
  24. data/lib/factory_girl/deprecated.rb +18 -0
  25. data/lib/factory_girl/factory.rb +196 -0
  26. data/lib/factory_girl/find_definitions.rb +23 -0
  27. data/lib/factory_girl/proxy/attributes_for.rb +21 -0
  28. data/lib/factory_girl/proxy/build.rb +36 -0
  29. data/lib/factory_girl/proxy/create.rb +16 -0
  30. data/lib/factory_girl/proxy/stub.rb +64 -0
  31. data/lib/factory_girl/proxy.rb +87 -0
  32. data/lib/factory_girl/rails2.rb +1 -0
  33. data/lib/factory_girl/registry.rb +45 -0
  34. data/lib/factory_girl/sequence.rb +31 -0
  35. data/lib/factory_girl/step_definitions.rb +60 -0
  36. data/lib/factory_girl/syntax/blueprint.rb +42 -0
  37. data/lib/factory_girl/syntax/default.rb +33 -0
  38. data/lib/factory_girl/syntax/generate.rb +73 -0
  39. data/lib/factory_girl/syntax/make.rb +41 -0
  40. data/lib/factory_girl/syntax/methods.rb +86 -0
  41. data/lib/factory_girl/syntax/sham.rb +45 -0
  42. data/lib/factory_girl/syntax/vintage.rb +152 -0
  43. data/lib/factory_girl/syntax.rb +12 -0
  44. data/lib/factory_girl/version.rb +4 -0
  45. data/lib/factory_girl.rb +54 -0
  46. data/spec/acceptance/acceptance_helper.rb +11 -0
  47. data/spec/acceptance/attribute_aliases_spec.rb +26 -0
  48. data/spec/acceptance/attributes_for_spec.rb +48 -0
  49. data/spec/acceptance/build_spec.rb +35 -0
  50. data/spec/acceptance/build_stubbed_spec.rb +79 -0
  51. data/spec/acceptance/callbacks_spec.rb +53 -0
  52. data/spec/acceptance/create_spec.rb +67 -0
  53. data/spec/acceptance/default_strategy_spec.rb +27 -0
  54. data/spec/acceptance/definition_spec.rb +28 -0
  55. data/spec/acceptance/parent_spec.rb +39 -0
  56. data/spec/acceptance/sequence_spec.rb +34 -0
  57. data/spec/acceptance/syntax/blueprint_spec.rb +32 -0
  58. data/spec/acceptance/syntax/generate_spec.rb +60 -0
  59. data/spec/acceptance/syntax/make_spec.rb +35 -0
  60. data/spec/acceptance/syntax/sham_spec.rb +44 -0
  61. data/spec/acceptance/syntax/vintage_spec.rb +224 -0
  62. data/spec/factory_girl/aliases_spec.rb +33 -0
  63. data/spec/factory_girl/attribute/association_spec.rb +33 -0
  64. data/spec/factory_girl/attribute/callback_spec.rb +23 -0
  65. data/spec/factory_girl/attribute/dynamic_spec.rb +60 -0
  66. data/spec/factory_girl/attribute/implicit_spec.rb +50 -0
  67. data/spec/factory_girl/attribute/sequence_spec.rb +21 -0
  68. data/spec/factory_girl/attribute/static_spec.rb +29 -0
  69. data/spec/factory_girl/attribute_spec.rb +39 -0
  70. data/spec/factory_girl/definition_proxy_spec.rb +129 -0
  71. data/spec/factory_girl/deprecated_spec.rb +66 -0
  72. data/spec/factory_girl/factory_spec.rb +374 -0
  73. data/spec/factory_girl/find_definitions_spec.rb +100 -0
  74. data/spec/factory_girl/proxy/attributes_for_spec.rb +52 -0
  75. data/spec/factory_girl/proxy/build_spec.rb +86 -0
  76. data/spec/factory_girl/proxy/create_spec.rb +107 -0
  77. data/spec/factory_girl/proxy/stub_spec.rb +80 -0
  78. data/spec/factory_girl/proxy_spec.rb +102 -0
  79. data/spec/factory_girl/registry_spec.rb +83 -0
  80. data/spec/factory_girl/sequence_spec.rb +96 -0
  81. data/spec/factory_girl_spec.rb +17 -0
  82. data/spec/spec_helper.rb +93 -0
  83. metadata +294 -0
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Proxy::AttributesFor do
4
+ before do
5
+ @proxy = FactoryGirl::Proxy::AttributesFor.new(@class)
6
+ end
7
+
8
+ describe "when asked to associate with another factory" do
9
+ before do
10
+ stub(FactoryGirl).create
11
+ @proxy.associate(:owner, :user, {})
12
+ end
13
+
14
+ it "should not set a value for the association" do
15
+ (@proxy.result(nil).key?(:owner)).should_not be
16
+ end
17
+ end
18
+
19
+ it "should return nil when building an association" do
20
+ @proxy.association(:user).should be_nil
21
+ end
22
+
23
+ it "should not call Factory.create when building an association" do
24
+ stub(FactoryGirl).create
25
+ @proxy.association(:user).should be_nil
26
+ FactoryGirl.should have_received.create.never
27
+ end
28
+
29
+ it "should always return nil when building an association" do
30
+ @proxy.set(:association, 'x')
31
+ @proxy.association(:user).should be_nil
32
+ end
33
+
34
+ it "should return a hash when asked for the result" do
35
+ @proxy.result(nil).should be_kind_of(Hash)
36
+ end
37
+
38
+ describe "after setting an attribute" do
39
+ before do
40
+ @proxy.set(:attribute, 'value')
41
+ end
42
+
43
+ it "should set that value in the resulting hash" do
44
+ @proxy.result(nil)[:attribute].should == 'value'
45
+ end
46
+
47
+ it "should return that value when asked for that attribute" do
48
+ @proxy.get(:attribute).should == 'value'
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Proxy::Build do
4
+ before do
5
+ @class = Class.new
6
+ @instance = "built-instance"
7
+
8
+ stub(@class).new { @instance }
9
+ stub(@instance).attribute { 'value' }
10
+ stub(@instance, :attribute=)
11
+ stub(@instance, :owner=)
12
+
13
+ @proxy = FactoryGirl::Proxy::Build.new(@class)
14
+ end
15
+
16
+ it "should instantiate the class" do
17
+ @class.should have_received.new
18
+ end
19
+
20
+ describe "when asked to associate with another factory" do
21
+ before do
22
+ @association = "associated-instance"
23
+ @associated_factory = "associated-factory"
24
+ stub(FactoryGirl).factory_by_name { @associated_factory }
25
+ stub(@associated_factory).run { @association }
26
+ @overrides = { 'attr' => 'value' }
27
+ @proxy.associate(:owner, :user, @overrides)
28
+ end
29
+
30
+ it "should create the associated instance" do
31
+ @associated_factory.should have_received.run(FactoryGirl::Proxy::Create, @overrides)
32
+ end
33
+
34
+ it "should set the associated instance" do
35
+ @instance.should have_received.method_missing(:owner=, @association)
36
+ end
37
+ end
38
+
39
+ it "should run create when building an association" do
40
+ association = "associated-instance"
41
+ associated_factory = "associated-factory"
42
+ stub(FactoryGirl).factory_by_name { associated_factory }
43
+ stub(associated_factory).run { association }
44
+ overrides = { 'attr' => 'value' }
45
+ @proxy.association(:user, overrides).should == association
46
+ associated_factory.should have_received.run(FactoryGirl::Proxy::Create, overrides)
47
+ end
48
+
49
+ it "should return the built instance when asked for the result" do
50
+ @proxy.result(nil).should == @instance
51
+ end
52
+
53
+ it "should run the :after_build callback when retrieving the result" do
54
+ spy = Object.new
55
+ stub(spy).foo
56
+ @proxy.add_callback(:after_build, proc{ spy.foo })
57
+ @proxy.result(nil)
58
+ spy.should have_received.foo
59
+ end
60
+
61
+ describe "when setting an attribute" do
62
+ before do
63
+ stub(@instance).attribute = 'value'
64
+ @proxy.set(:attribute, 'value')
65
+ end
66
+
67
+ it "should set that value" do
68
+ @instance.should have_received.method_missing(:attribute=, 'value')
69
+ end
70
+ end
71
+
72
+ describe "when getting an attribute" do
73
+ before do
74
+ @result = @proxy.get(:attribute)
75
+ end
76
+
77
+ it "should ask the built class for the value" do
78
+ @instance.should have_received.attribute
79
+ end
80
+
81
+ it "should return the value for that attribute" do
82
+ @result.should == 'value'
83
+ end
84
+ end
85
+ end
86
+
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Proxy::Create do
4
+ before do
5
+ @class = Class.new
6
+ @instance = "built-instance"
7
+
8
+ stub(@class).new { @instance }
9
+ stub(@instance).attribute { 'value' }
10
+ stub(@instance, :attribute=)
11
+ stub(@instance, :owner=)
12
+ stub(@instance).save!
13
+
14
+ @proxy = FactoryGirl::Proxy::Create.new(@class)
15
+ end
16
+
17
+ it "should instantiate the class" do
18
+ @class.should have_received.new
19
+ end
20
+
21
+ describe "when asked to associate with another factory" do
22
+ before do
23
+ @association = "associated-instance"
24
+ @associated_factory = "associated-factory"
25
+ stub(FactoryGirl).factory_by_name { @associated_factory }
26
+ stub(@associated_factory).run { @association }
27
+ @overrides = { 'attr' => 'value' }
28
+ @proxy.associate(:owner, :user, @overrides)
29
+ end
30
+
31
+ it "should create the associated instance" do
32
+ @associated_factory.should have_received.run(FactoryGirl::Proxy::Create, @overrides)
33
+ end
34
+
35
+ it "should set the associated instance" do
36
+ @instance.should have_received.method_missing(:owner=, @association)
37
+ end
38
+ end
39
+
40
+ it "should run create when building an association" do
41
+ association = "associated-instance"
42
+ associated_factory = "associated-factory"
43
+ stub(FactoryGirl).factory_by_name { associated_factory }
44
+ stub(associated_factory).run { association }
45
+ overrides = { 'attr' => 'value' }
46
+ @proxy.association(:user, overrides).should == association
47
+ associated_factory.should have_received.run(FactoryGirl::Proxy::Create, overrides)
48
+ end
49
+
50
+ describe "when asked for the result" do
51
+ before do
52
+ @build_spy = Object.new
53
+ @create_spy = Object.new
54
+ stub(@build_spy).foo
55
+ stub(@create_spy).foo
56
+ @proxy.add_callback(:after_build, proc{ @build_spy.foo })
57
+ @proxy.add_callback(:after_create, proc{ @create_spy.foo })
58
+ @result = @proxy.result(nil)
59
+ end
60
+
61
+ it "should save the instance" do
62
+ @instance.should have_received.save!
63
+ end
64
+
65
+ it "should return the built instance" do
66
+ @result.should == @instance
67
+ end
68
+
69
+ it "should run both the build and the create callbacks" do
70
+ @build_spy.should have_received.foo
71
+ @create_spy.should have_received.foo
72
+ end
73
+ end
74
+
75
+ it "runs a custom create block" do
76
+ block = 'custom create block'
77
+ stub(block).call
78
+ stub(@instance).save! { raise }
79
+ instance = @proxy.result(block)
80
+ block.should have_received.call(instance)
81
+ end
82
+
83
+ describe "when setting an attribute" do
84
+ before do
85
+ @proxy.set(:attribute, 'value')
86
+ end
87
+
88
+ it "should set that value" do
89
+ @instance.should have_received.method_missing(:attribute=, 'value')
90
+ end
91
+ end
92
+
93
+ describe "when getting an attribute" do
94
+ before do
95
+ @result = @proxy.get(:attribute)
96
+ end
97
+
98
+ it "should ask the built class for the value" do
99
+ @instance.should have_received.attribute
100
+ end
101
+
102
+ it "should return the value for that attribute" do
103
+ @result.should == 'value'
104
+ end
105
+ end
106
+ end
107
+
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Proxy::Stub do
4
+ before do
5
+ @class = "class"
6
+ @instance = "instance"
7
+ stub(@class).new { @instance }
8
+ stub(@instance, :id=)
9
+ stub(@instance).id { 42 }
10
+ stub(@instance).reload { @instance.connection.reload }
11
+
12
+ @stub = FactoryGirl::Proxy::Stub.new(@class)
13
+ end
14
+
15
+ it "should not be a new record" do
16
+ @stub.result(nil).should_not be_new_record
17
+ end
18
+
19
+ it "should not be able to connect to the database" do
20
+ lambda { @stub.result(nil).reload }.should raise_error(RuntimeError)
21
+ end
22
+
23
+ describe "when a user factory exists" do
24
+ before do
25
+ @user = "user"
26
+ stub(FactoryGirl).factory_by_name { @associated_factory }
27
+ @associated_factory = 'associate-factory'
28
+ end
29
+
30
+ describe "when asked to associate with another factory" do
31
+ before do
32
+ stub(@instance).owner { @user }
33
+ mock(@associated_factory).run(FactoryGirl::Proxy::Stub, {}) { @user }
34
+ mock(@stub).set(:owner, @user)
35
+
36
+ @stub.associate(:owner, :user, {})
37
+ end
38
+
39
+ it "should set a value for the association" do
40
+ @stub.result(nil).owner.should == @user
41
+ end
42
+ end
43
+
44
+ it "should return the association when building one" do
45
+ mock(@associated_factory).run(FactoryGirl::Proxy::Stub, {}) { @user }
46
+ @stub.association(:user).should == @user
47
+ end
48
+
49
+ describe "when asked for the result" do
50
+ it "should return the actual instance" do
51
+ @stub.result(nil).should == @instance
52
+ end
53
+
54
+ it "should run the :after_stub callback" do
55
+ @spy = Object.new
56
+ stub(@spy).foo
57
+ @stub.add_callback(:after_stub, proc{ @spy.foo })
58
+ @stub.result(nil)
59
+ @spy.should have_received.foo
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "with an existing attribute" do
65
+ before do
66
+ @value = "value"
67
+ mock(@instance).send(:attribute) { @value }
68
+ mock(@instance).send(:attribute=, @value)
69
+ @stub.set(:attribute, @value)
70
+ end
71
+
72
+ it "should to the resulting object" do
73
+ @stub.attribute.should == 'value'
74
+ end
75
+
76
+ it "should return that value when asked for that attribute" do
77
+ @stub.get(:attribute).should == @value
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Proxy do
4
+ before do
5
+ @proxy = FactoryGirl::Proxy.new(Class.new)
6
+ end
7
+
8
+ it "should do nothing when asked to set an attribute to a value" do
9
+ lambda { @proxy.set(:name, 'a name') }.should_not raise_error
10
+ end
11
+
12
+ it "should return nil when asked for an attribute" do
13
+ @proxy.get(:name).should be_nil
14
+ end
15
+
16
+ it "should call get for a missing method" do
17
+ mock(@proxy).get(:name) { "it's a name" }
18
+ @proxy.name.should == "it's a name"
19
+ end
20
+
21
+ it "should store ignored attributes" do
22
+ @proxy.ignore(:name, "it's a name").should == "it's a name"
23
+ end
24
+
25
+ it "should get an ignored attribute" do
26
+ @proxy.ignore(:name, "it's a name")
27
+ @proxy.get(:name).should == "it's a name"
28
+ end
29
+
30
+ it "should do nothing when asked to associate with another factory" do
31
+ lambda { @proxy.associate(:owner, :user, {}) }.should_not raise_error
32
+ end
33
+
34
+ it "should raise an error when asked for the result" do
35
+ lambda { @proxy.result(nil) }.should raise_error(NotImplementedError)
36
+ end
37
+
38
+ describe "when adding callbacks" do
39
+ before do
40
+ @first_block = proc{ 'block 1' }
41
+ @second_block = proc{ 'block 2' }
42
+ end
43
+ it "should add a callback" do
44
+ @proxy.add_callback(:after_create, @first_block)
45
+ @proxy.callbacks[:after_create].should be_eql([@first_block])
46
+ end
47
+
48
+ it "should add multiple callbacks of the same name" do
49
+ @proxy.add_callback(:after_create, @first_block)
50
+ @proxy.add_callback(:after_create, @second_block)
51
+ @proxy.callbacks[:after_create].should be_eql([@first_block, @second_block])
52
+ end
53
+
54
+ it "should add multiple callbacks of different names" do
55
+ @proxy.add_callback(:after_create, @first_block)
56
+ @proxy.add_callback(:after_build, @second_block)
57
+ @proxy.callbacks[:after_create].should be_eql([@first_block])
58
+ @proxy.callbacks[:after_build].should be_eql([@second_block])
59
+ end
60
+ end
61
+
62
+ describe "when running callbacks" do
63
+ before do
64
+ @first_spy = Object.new
65
+ @second_spy = Object.new
66
+ stub(@first_spy).foo
67
+ stub(@second_spy).foo
68
+ end
69
+
70
+ it "should run all callbacks with a given name" do
71
+ @proxy.add_callback(:after_create, proc{ @first_spy.foo })
72
+ @proxy.add_callback(:after_create, proc{ @second_spy.foo })
73
+ @proxy.run_callbacks(:after_create)
74
+ @first_spy.should have_received.foo
75
+ @second_spy.should have_received.foo
76
+ end
77
+
78
+ it "should only run callbacks with a given name" do
79
+ @proxy.add_callback(:after_create, proc{ @first_spy.foo })
80
+ @proxy.add_callback(:after_build, proc{ @second_spy.foo })
81
+ @proxy.run_callbacks(:after_create)
82
+ @first_spy.should have_received.foo
83
+ @second_spy.should_not have_received.foo
84
+ end
85
+
86
+ it "should pass in the instance if the block takes an argument" do
87
+ @proxy.instance_variable_set("@instance", @first_spy)
88
+ @proxy.add_callback(:after_create, proc{|spy| spy.foo })
89
+ @proxy.run_callbacks(:after_create)
90
+ @first_spy.should have_received.foo
91
+ end
92
+
93
+ it "should pass in the proxy if the block takes two arguments" do
94
+ @proxy.instance_variable_set("@instance", @first_spy)
95
+ stub(@proxy).bar
96
+ @proxy.add_callback(:after_create, proc {|spy, proxy| spy.foo; proxy.bar })
97
+ @proxy.run_callbacks(:after_create)
98
+ @first_spy.should have_received.foo
99
+ @proxy.should have_received.bar
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Registry do
4
+ let(:factory) { FactoryGirl::Factory.new(:object) }
5
+
6
+ subject { FactoryGirl::Registry.new }
7
+
8
+ it "finds a registered a factory" do
9
+ subject.add(factory)
10
+ subject.find(factory.name).should == factory
11
+ end
12
+
13
+ it "raises when finding an unregistered factory" do
14
+ expect { subject.find(:bogus) }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it "adds and returns a factory" do
18
+ subject.add(factory).should == factory
19
+ end
20
+
21
+ it "knows that a factory is registered by symbol" do
22
+ subject.add(factory)
23
+ subject.should be_registered(factory.name.to_sym)
24
+ end
25
+
26
+ it "knows that a factory is registered by string" do
27
+ subject.add(factory)
28
+ subject.should be_registered(factory.name.to_s)
29
+ end
30
+
31
+ it "knows that a factory isn't registered" do
32
+ subject.should_not be_registered("bogus")
33
+ end
34
+
35
+ it "can be accessed like a hash" do
36
+ subject.add(factory)
37
+ subject[factory.name].should == factory
38
+ end
39
+
40
+ it "iterates registered factories" do
41
+ other_factory = FactoryGirl::Factory.new(:string)
42
+ subject.add(factory)
43
+ subject.add(other_factory)
44
+ result = []
45
+
46
+ subject.each do |value|
47
+ result << value
48
+ end
49
+
50
+ result.should =~ [factory, other_factory]
51
+ end
52
+
53
+ it "registers an sequence" do
54
+ sequence = FactoryGirl::Sequence.new(:email) { |n| "somebody#{n}@example.com" }
55
+ subject.add(sequence)
56
+ subject.find(:email).should == sequence
57
+ end
58
+
59
+ it "doesn't allow a duplicate name" do
60
+ expect { 2.times { subject.add(factory) } }.
61
+ to raise_error(FactoryGirl::DuplicateDefinitionError)
62
+ end
63
+
64
+ it "registers aliases" do
65
+ aliases = [:thing, :widget]
66
+ factory = FactoryGirl::Factory.new(:object, :aliases => aliases)
67
+ subject.add(factory)
68
+ aliases.each do |name|
69
+ subject.find(name).should == factory
70
+ end
71
+ end
72
+
73
+ it "is enumerable" do
74
+ should be_kind_of(Enumerable)
75
+ end
76
+
77
+ it "clears registered factories" do
78
+ subject.add(factory)
79
+ subject.clear
80
+ subject.count.should == 0
81
+ end
82
+ end
83
+
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl::Sequence do
4
+ describe "a basic sequence" do
5
+ before do
6
+ @name = :test
7
+ @sequence = FactoryGirl::Sequence.new(@name) {|n| "=#{n}" }
8
+ end
9
+
10
+ it "has a name" do
11
+ @sequence.name.should == @name
12
+ end
13
+
14
+ it "has names" do
15
+ @sequence.names.should == [@name]
16
+ end
17
+
18
+ it "should start with a value of 1" do
19
+ @sequence.next.should == "=1"
20
+ end
21
+
22
+ it "responds to default_strategy" do
23
+ @sequence.default_strategy.should == :create
24
+ end
25
+
26
+ describe "after being called" do
27
+ before do
28
+ @sequence.next
29
+ end
30
+
31
+ it "should use the next value" do
32
+ @sequence.next.should == "=2"
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "a custom sequence" do
38
+ before do
39
+ @sequence = FactoryGirl::Sequence.new(:name, "A") {|n| "=#{n}" }
40
+ end
41
+
42
+ it "should start with a value of A" do
43
+ @sequence.next.should == "=A"
44
+ end
45
+
46
+ describe "after being called" do
47
+ before do
48
+ @sequence.next
49
+ end
50
+
51
+ it "should use the next value" do
52
+ @sequence.next.should == "=B"
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "a basic sequence without a block" do
58
+ before do
59
+ @sequence = FactoryGirl::Sequence.new(:name)
60
+ end
61
+
62
+ it "should start with a value of 1" do
63
+ @sequence.next.should == 1
64
+ end
65
+
66
+ describe "after being called" do
67
+ before do
68
+ @sequence.next
69
+ end
70
+
71
+ it "should use the next value" do
72
+ @sequence.next.should == 2
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "a custom sequence without a block" do
78
+ before do
79
+ @sequence = FactoryGirl::Sequence.new(:name, "A")
80
+ end
81
+
82
+ it "should start with a value of A" do
83
+ @sequence.next.should == "A"
84
+ end
85
+
86
+ describe "after being called" do
87
+ before do
88
+ @sequence.next
89
+ end
90
+
91
+ it "should use the next value" do
92
+ @sequence.next.should == "B"
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe FactoryGirl do
4
+ let(:factory) { FactoryGirl::Factory.new(:object) }
5
+ let(:sequence) { FactoryGirl::Sequence.new(:email) }
6
+
7
+ it "finds a registered a factory" do
8
+ FactoryGirl.register_factory(factory)
9
+ FactoryGirl.factory_by_name(factory.name).should == factory
10
+ end
11
+
12
+ it "finds a registered a sequence" do
13
+ FactoryGirl.register_sequence(sequence)
14
+ FactoryGirl.sequence_by_name(sequence.name).should == sequence
15
+ end
16
+ end
17
+