Permalink
Browse files

Update tests to use new syntax, and add test coverage for people usin…

…g the legacy syntax.
  • Loading branch information...
1 parent d2db76a commit 5ade3decfc3b4d2efee8f60532e3a296aa931aac @cmeiklejohn committed Sep 3, 2011
Showing with 59 additions and 36 deletions.
  1. +54 −31 spec/models/garage_spec.rb
  2. +5 −5 spec/support/watchmakers.rb
View
@@ -3,45 +3,68 @@
require 'spec_helper'
describe Garage do
- it "should create some garages from the lambda based watchmaker" do
- Watchmaker.construct(:two_garages)
- Garage.all.count.should == 2
- end
- it "should the result of the lambda evaluation when constructing that way" do
- Watchmaker.construct(:two_cars).first.should == 2
- Car.all.count.should == 2
+ describe "when using the builder" do
+ it "should build some garages from the lambda based watchmaker" do
+ Watchmaker.build(:two_garages).count.should == 2
+ Garage.all.count.should == 0
+ end
end
- it "should create a garage from the factory based watchmaker" do
- Watchmaker.construct(:garage)
- Garage.all.count.should == 1
- end
+ describe "when using the creator" do
+ it "should create some garages from the lambda based watchmaker" do
+ Watchmaker.create(:two_garages)
+ Garage.all.count.should == 2
+ end
- it "return the objects created from a watchmaker" do
- Watchmaker.construct(:garage).first.should == Garage.first
- end
+ it "should the result of the lambda evaluation when constructing that way" do
+ Watchmaker.create(:two_cars).first.should == 2
+ Car.all.count.should == 2
+ end
- it "should create a garage and it's from the factory based watchmaker" do
- Watchmaker.construct(:car_in_garage).map do |o|
- o.class.to_s
- end.should == ["Garage", "Car", "Array"]
+ it "should create a garage from the factory based watchmaker" do
+ Watchmaker.create(:garage)
+ Garage.all.count.should == 1
+ end
- Car.all.count.should == 1
- Garage.all.count.should == 1
- Garage.first.cars.should include(Car.first)
- end
+ it "return the objects created from a watchmaker" do
+ Watchmaker.create(:garage).first.should == Garage.first
+ end
+
+ it "should create a garage and it's from the factory based watchmaker" do
+ Watchmaker.create(:car_in_garage).map do |o|
+ o.class.to_s
+ end.should == ["Garage", "Car", "Array"]
- it "should create a car from the watchmaker based watchmaker" do
- Watchmaker.construct(:car_with_garage).first.should be_a_kind_of Car
- Car.all.count.should == 1
- Garage.all.count.should == 1
+ Car.all.count.should == 1
+ Garage.all.count.should == 1
+ Garage.first.cars.should include(Car.first)
+ end
+
+ it "should create a car from the watchmaker based watchmaker" do
+ Watchmaker.create(:car_with_garage).first.should be_a_kind_of Car
+ Car.all.count.should == 1
+ Garage.all.count.should == 1
+ end
+
+ it "should be able to use the new syntax to build based on factories or watchmakers" do
+ Watchmaker.create(:two_cars_and_two_garages)
+ Garage.all.count.should == 2
+ Car.all.count.should == 2
+ Garage.last.cars.count.should == 2
+ end
end
- it "should be able to use the new syntax to build based on factories or watchmakers" do
- Watchmaker.construct(:two_cars_and_two_garages)
- Garage.all.count.should == 2
- Car.all.count.should == 2
- Garage.last.cars.count.should == 2
+ describe "when using the legacy syntax" do
+ it "should build some garages from the lambda based watchmaker" do
+ Watchmaker.assemble(:two_garages).count.should == 2
+ Garage.all.count.should == 0
+ end
+
+ it "should create some garages from the lambda based watchmaker" do
+ Watchmaker.construct(:two_garages)
+ Garage.all.count.should == 2
+ end
end
+
end
@@ -12,17 +12,17 @@
end
end
-Watchmaker.learn :garage, :factories => [:garage]
+Watchmaker.define :garage, :factories => [:garage]
-Watchmaker.learn :car_with_garage, :factories => [:car], :watchmakers => [:garage]
+Watchmaker.define :car_with_garage, :factories => [:car], :watchmakers => [:garage]
-Watchmaker.learn :car_in_garage, :factories => [:garage, :car] do |garage, car|
+Watchmaker.define :car_in_garage, :factories => [:garage, :car] do |garage, car|
garage.cars << car
end
-Watchmaker.learn :two_garages, :factories => [:garage, :garage]
+Watchmaker.define :two_garages, :factories => [:garage, :garage]
-Watchmaker.learn :two_cars_and_two_garages => [:two_garages, :car, :car] do |garages, car1, car2|
+Watchmaker.define :two_cars_and_two_garages => [:two_garages, :car, :car] do |garages, car1, car2|
garages.each do |garage|
garage.cars << car1
garage.cars << car2

0 comments on commit 5ade3de

Please sign in to comment.