thoughtbot-factory_girl 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTION_GUIDELINES.rdoc +4 -5
- data/README.rdoc +6 -6
- data/Rakefile +11 -14
- data/lib/factory_girl/attribute.rb +3 -2
- data/lib/factory_girl/attribute/dynamic.rb +5 -2
- data/lib/factory_girl/proxy/stub.rb +33 -12
- data/lib/factory_girl/sequence.rb +3 -0
- data/spec/factory_girl/aliases_spec.rb +29 -0
- data/spec/factory_girl/attribute/association_spec.rb +25 -0
- data/spec/factory_girl/attribute/dynamic_spec.rb +49 -0
- data/spec/factory_girl/attribute/static_spec.rb +29 -0
- data/spec/factory_girl/attribute_spec.rb +30 -0
- data/spec/factory_girl/factory_spec.rb +490 -0
- data/spec/factory_girl/proxy/attributes_for_spec.rb +52 -0
- data/spec/factory_girl/proxy/build_spec.rb +73 -0
- data/spec/factory_girl/proxy/create_spec.rb +83 -0
- data/spec/factory_girl/proxy/stub_spec.rb +69 -0
- data/spec/factory_girl/proxy_spec.rb +28 -0
- data/spec/factory_girl/sequence_spec.rb +66 -0
- data/spec/factory_girl/syntax/blueprint_spec.rb +34 -0
- data/spec/factory_girl/syntax/generate_spec.rb +57 -0
- data/spec/factory_girl/syntax/make_spec.rb +35 -0
- data/spec/factory_girl/syntax/sham_spec.rb +35 -0
- data/spec/integration_spec.rb +265 -0
- data/{test → spec}/models.rb +0 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +12 -5
- metadata +42 -43
- data/test/aliases_test.rb +0 -29
- data/test/association_attribute_test.rb +0 -31
- data/test/attribute_test.rb +0 -32
- data/test/attributes_for_strategy_test.rb +0 -55
- data/test/build_strategy_test.rb +0 -79
- data/test/create_strategy_test.rb +0 -90
- data/test/dynamic_attribute_test.rb +0 -41
- data/test/factory_test.rb +0 -513
- data/test/integration_test.rb +0 -235
- data/test/sequence_test.rb +0 -76
- data/test/static_attribute_test.rb +0 -33
- data/test/strategy_test.rb +0 -33
- data/test/stub_strategy_test.rb +0 -61
- data/test/syntax/blueprint_test.rb +0 -39
- data/test/syntax/generate_test.rb +0 -63
- data/test/syntax/make_test.rb +0 -39
- data/test/syntax/sham_test.rb +0 -40
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'factory_girl/syntax/generate'
|
4
|
-
|
5
|
-
class GenerateSyntaxTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
context "a factory" do
|
8
|
-
setup do
|
9
|
-
Factory.define :user do |factory|
|
10
|
-
factory.first_name 'Bill'
|
11
|
-
factory.last_name 'Nye'
|
12
|
-
factory.email 'science@guys.net'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
teardown do
|
17
|
-
Factory.factories.clear
|
18
|
-
end
|
19
|
-
|
20
|
-
should "not raise an error when generating an invalid instance" do
|
21
|
-
assert_nothing_raised { User.generate(:first_name => nil) }
|
22
|
-
end
|
23
|
-
|
24
|
-
should "raise an error when forcefully generating an invalid instance" do
|
25
|
-
assert_raise ActiveRecord::RecordInvalid do
|
26
|
-
User.generate!(:first_name => nil)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
%w(generate generate! spawn).each do |method|
|
31
|
-
should "yield a generated instance when using #{method} with a block" do
|
32
|
-
instance = nil
|
33
|
-
User.send(method) {|instance| }
|
34
|
-
assert_kind_of User, instance
|
35
|
-
end
|
36
|
-
|
37
|
-
context "after generating an instance using #{method}" do
|
38
|
-
setup do
|
39
|
-
@instance = User.send(method, :last_name => 'Rye')
|
40
|
-
end
|
41
|
-
|
42
|
-
should "use attributes from the factory" do
|
43
|
-
assert_equal 'Bill', @instance.first_name
|
44
|
-
end
|
45
|
-
|
46
|
-
should "use attributes passed to generate" do
|
47
|
-
assert_equal 'Rye', @instance.last_name
|
48
|
-
end
|
49
|
-
|
50
|
-
if method == 'spawn'
|
51
|
-
should "not save the record" do
|
52
|
-
assert @instance.new_record?
|
53
|
-
end
|
54
|
-
else
|
55
|
-
should "save the record" do
|
56
|
-
assert !@instance.new_record?
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
data/test/syntax/make_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'factory_girl/syntax/make'
|
4
|
-
|
5
|
-
class MakeSyntaxTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
context "a factory" do
|
8
|
-
setup do
|
9
|
-
Factory.define :user do |factory|
|
10
|
-
factory.first_name 'Bill'
|
11
|
-
factory.last_name 'Nye'
|
12
|
-
factory.email 'science@guys.net'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
teardown do
|
17
|
-
Factory.factories.clear
|
18
|
-
end
|
19
|
-
|
20
|
-
context "after making an instance" do
|
21
|
-
setup do
|
22
|
-
@instance = User.make(:last_name => 'Rye')
|
23
|
-
end
|
24
|
-
|
25
|
-
should "use attributes from the factory" do
|
26
|
-
assert_equal 'Bill', @instance.first_name
|
27
|
-
end
|
28
|
-
|
29
|
-
should "use attributes passed to make" do
|
30
|
-
assert_equal 'Rye', @instance.last_name
|
31
|
-
end
|
32
|
-
|
33
|
-
should "save the record" do
|
34
|
-
assert !@instance.new_record?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/test/syntax/sham_test.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'factory_girl/syntax/sham'
|
4
|
-
|
5
|
-
class ShamSyntaxTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
context "a factory" do
|
8
|
-
setup do
|
9
|
-
Sham.name { "Name" }
|
10
|
-
Sham.email { "somebody#{rand(5)}@example.com" }
|
11
|
-
|
12
|
-
Factory.define :user do |factory|
|
13
|
-
factory.first_name { Sham.name }
|
14
|
-
factory.last_name { Sham.name }
|
15
|
-
factory.email { Sham.email }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
teardown do
|
20
|
-
Factory.factories.clear
|
21
|
-
Factory.sequences.clear
|
22
|
-
end
|
23
|
-
|
24
|
-
context "after making an instance" do
|
25
|
-
setup do
|
26
|
-
@instance = Factory(:user, :last_name => 'Rye')
|
27
|
-
end
|
28
|
-
|
29
|
-
should "support a sham called 'name'" do
|
30
|
-
assert_equal 'Name', @instance.first_name
|
31
|
-
end
|
32
|
-
|
33
|
-
should "use the sham for the email" do
|
34
|
-
assert_match /somebody\d@example.com/, @instance.email
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|