fabrication 0.2.1 → 0.2.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 CHANGED
@@ -52,4 +52,4 @@ So you already have a company fabricator, but you need one that specifically gen
52
52
  type "LLC"
53
53
  end
54
54
 
55
- Setting the :from option will inherit the class and all the attributes from the named Fabricator.
55
+ Setting the :from option will inherit the class and all the attributes from the named Fabricator. Even if you haven't defined a :company Fabricator yet, it will still work as long as it references an actual class name.
data/lib/fabrication.rb CHANGED
@@ -12,6 +12,7 @@ module Fabrication
12
12
  class << self
13
13
 
14
14
  def schematic(name, options, &block)
15
+ raise DuplicateFabricatorError if fabricators.has_key?(name)
15
16
  parent = fabricators[options[:from]]
16
17
  if parent
17
18
  class_name = parent.class_name
@@ -53,6 +54,7 @@ module Fabrication
53
54
 
54
55
  private
55
56
 
57
+ @@fabricators = nil
56
58
  def fabricators
57
59
  @@fabricators ||= {}
58
60
  end
@@ -1,5 +1,7 @@
1
1
  module Fabrication
2
2
 
3
+ class DuplicateFabricatorError < StandardError; end
4
+
3
5
  class UnknownFabricatorError < StandardError; end
4
6
 
5
7
  end
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -117,7 +117,7 @@ describe Fabrication do
117
117
  before(:all) { TestMigration.up }
118
118
  after(:all) { TestMigration.down }
119
119
 
120
- before do
120
+ before(:all) do
121
121
  Fabricator(:company) do
122
122
  name { Faker::Company.name }
123
123
  divisions(:force => true, :count => 4) { Fabricate(:division) }
@@ -151,13 +151,15 @@ describe Fabrication do
151
151
 
152
152
  context 'with a mongoid document' do
153
153
 
154
- let(:author) do
154
+ before(:all) do
155
155
  Fabricator(:author) do
156
156
  name "George Orwell"
157
157
  books(:count => 4) { |author, i| "book title #{i}" }
158
- end.fabricate
158
+ end
159
159
  end
160
160
 
161
+ let(:author) { Fabricate(:author) }
162
+
161
163
  it "sets the author name" do
162
164
  author.name.should == "George Orwell"
163
165
  end
@@ -197,7 +199,6 @@ describe Fabrication do
197
199
  context 'and a class name as a parent' do
198
200
 
199
201
  before(:all) do
200
- Fabrication.clear_definitions
201
202
  Fabricator(:hemingway, :from => :author) do
202
203
  name 'Ernest Hemingway'
203
204
  end
@@ -230,4 +231,30 @@ describe Fabrication do
230
231
 
231
232
  end
232
233
 
234
+ context 'when defining a fabricator twice' do
235
+
236
+ before(:all) do
237
+ Fabricator(:author) {}
238
+ end
239
+
240
+ it 'throws an error' do
241
+ lambda { Fabricator(:author) {} }.should raise_error(Fabrication::DuplicateFabricatorError)
242
+ end
243
+
244
+ end
245
+
246
+ context 'when generating from a non-existant fabricator' do
247
+
248
+ it 'throws an error' do
249
+ lambda { Fabricate(:author) }.should raise_error(Fabrication::UnknownFabricatorError)
250
+ end
251
+
252
+ end
253
+
254
+ context 'defining a fabricator without a block' do
255
+
256
+ it 'works fine'
257
+
258
+ end
259
+
233
260
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ require 'mongoid'
11
11
 
12
12
  Spec::Runner.configure do |config|
13
13
  config.before(:all) do
14
+ Fabrication.clear_definitions
14
15
  Author.delete_all
15
16
  end
16
17
  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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Elliott