fabrication 0.6.0 → 0.6.2
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.
- data/README.markdown +0 -15
- data/lib/fabrication.rb +11 -74
- data/lib/fabrication/errors.rb +1 -1
- data/lib/fabrication/fabricator.rb +41 -21
- data/lib/fabrication/generator/base.rb +9 -11
- data/lib/fabrication/generator/mongoid.rb +4 -4
- data/lib/fabrication/schematic.rb +22 -13
- data/lib/fabrication/sequencer.rb +19 -0
- data/lib/fabrication/support.rb +13 -1
- data/lib/fabrication/version.rb +1 -1
- data/spec/fabrication_spec.rb +38 -105
- data/spec/fabricator_spec.rb +37 -28
- data/spec/generator/active_record_spec.rb +31 -30
- data/spec/generator/base_spec.rb +32 -27
- data/spec/generator/mongoid_spec.rb +17 -22
- data/spec/schematic_spec.rb +76 -74
- data/spec/sequence_spec.rb +5 -5
- data/spec/spec_helper.rb +0 -6
- data/spec/support/active_record.rb +4 -0
- data/spec/support/helper_objects.rb +15 -0
- data/spec/support/mongoid.rb +15 -0
- data/spec/support_spec.rb +61 -0
- metadata +6 -5
- data/spec/benchmark_spec.rb +0 -11
data/spec/sequence_spec.rb
CHANGED
@@ -27,14 +27,14 @@ describe "Fabricate.sequence" do
|
|
27
27
|
context 'with a name and starting number' do
|
28
28
|
|
29
29
|
it 'starts with the number provided' do
|
30
|
-
Fabricate.sequence(:
|
30
|
+
Fabricate.sequence(:higher, 69).should == 69
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'increments by one with each call' do
|
34
|
-
Fabricate.sequence(:
|
35
|
-
Fabricate.sequence(:
|
36
|
-
Fabricate.sequence(:
|
37
|
-
Fabricate.sequence(:
|
34
|
+
Fabricate.sequence(:higher).should == 70
|
35
|
+
Fabricate.sequence(:higher, 69).should == 71
|
36
|
+
Fabricate.sequence(:higher).should == 72
|
37
|
+
Fabricate.sequence(:higher).should == 73
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,18 @@
|
|
1
1
|
class Person
|
2
2
|
attr_accessor :age, :first_name, :last_name, :shoes
|
3
3
|
end
|
4
|
+
|
5
|
+
class Dog
|
6
|
+
attr_accessor :name, :breed
|
7
|
+
end
|
8
|
+
|
9
|
+
Fabricator(:person) do
|
10
|
+
first_name "John"
|
11
|
+
last_name { Faker::Name.last_name }
|
12
|
+
age { rand(100) }
|
13
|
+
shoes(:count => 10) { |person, i| "shoe #{i}" }
|
14
|
+
end
|
15
|
+
|
16
|
+
Fabricator(:greyhound, :from => :dog) do
|
17
|
+
breed "greyhound"
|
18
|
+
end
|
data/spec/support/mongoid.rb
CHANGED
@@ -31,3 +31,18 @@ class Book
|
|
31
31
|
|
32
32
|
embedded_in :author, :inverse_of => :books
|
33
33
|
end
|
34
|
+
|
35
|
+
Fabricator(:author) do
|
36
|
+
name 'George Orwell'
|
37
|
+
books(:count => 4) do |author, i|
|
38
|
+
Fabricate(:book, :title => "book title #{i}", :author => author)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Fabricator(:hemingway, :from => :author) do
|
43
|
+
name 'Ernest Hemingway'
|
44
|
+
end
|
45
|
+
|
46
|
+
Fabricator(:book) do
|
47
|
+
title "book title"
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fabrication::Support do
|
4
|
+
|
5
|
+
describe ".class_for" do
|
6
|
+
|
7
|
+
context "with a class that exists" do
|
8
|
+
|
9
|
+
it "returns the class for a class" do
|
10
|
+
Fabrication::Support.class_for(Object).should == Object
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the class for a class name string" do
|
14
|
+
Fabrication::Support.class_for('object').should == Object
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns the class for a class name symbol" do
|
18
|
+
Fabrication::Support.class_for(:object).should == Object
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with a class that doesn't exist" do
|
24
|
+
|
25
|
+
it "returns nil for a class name string" do
|
26
|
+
Fabrication::Support.class_for('your_mom').should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns nil for a class name symbol" do
|
30
|
+
Fabrication::Support.class_for(:your_mom).should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe ".find_definitions" do
|
38
|
+
|
39
|
+
before(:all) do
|
40
|
+
File.open("spec/fabricators.rb", "w") do |f|
|
41
|
+
f.write("Fabricator(:awesome_object, :from => :object)")
|
42
|
+
end
|
43
|
+
File.open("spec/fabricators/cool_object.rb", "w") do |f|
|
44
|
+
f.write("Fabricator(:cool_object, :from => :object)")
|
45
|
+
end
|
46
|
+
Fabrication::Support.find_definitions
|
47
|
+
File.delete("spec/fabricators.rb")
|
48
|
+
File.delete("spec/fabricators/cool_object.rb")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has an awesome object" do
|
52
|
+
Fabrication::Fabricator.schematics[:awesome_object].should be
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has a cool object" do
|
56
|
+
Fabrication::Fabricator.schematics[:cool_object].should be
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Elliott
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-16 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -130,10 +130,10 @@ files:
|
|
130
130
|
- lib/fabrication/generator/base.rb
|
131
131
|
- lib/fabrication/generator/mongoid.rb
|
132
132
|
- lib/fabrication/schematic.rb
|
133
|
+
- lib/fabrication/sequencer.rb
|
133
134
|
- lib/fabrication/support.rb
|
134
135
|
- lib/fabrication/version.rb
|
135
136
|
- lib/fabrication.rb
|
136
|
-
- spec/benchmark_spec.rb
|
137
137
|
- spec/fabrication_spec.rb
|
138
138
|
- spec/fabricator_spec.rb
|
139
139
|
- spec/generator/active_record_spec.rb
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- spec/support/active_record.rb
|
147
147
|
- spec/support/helper_objects.rb
|
148
148
|
- spec/support/mongoid.rb
|
149
|
+
- spec/support_spec.rb
|
149
150
|
- README.markdown
|
150
151
|
has_rdoc: true
|
151
152
|
homepage: http://github.com/paulelliott/fabrication
|