Permalink
Browse files

Further build out of the test suite.

  • Loading branch information...
1 parent 5a29e90 commit f2899881c9b65ad23d7545cea61e058d7025792b @cmeiklejohn committed Aug 12, 2011
Showing with 25 additions and 7 deletions.
  1. +11 −4 spec/models/garage_spec.rb
  2. +8 −3 spec/spec_helper.rb
  3. +6 −0 spec/support/watchmakers.rb
View
15 spec/models/garage_spec.rb
@@ -8,25 +8,32 @@
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
+ end
+
it "should create a garage from the factory based watchmaker" do
Watchmaker.construct(:garage)
Garage.all.count.should == 1
end
it "return the objects created from a watchmaker" do
- Watchmaker.construct(:garage).first.should be_a_kind_of Garage
- Garage.all.count.should == 1
+ Watchmaker.construct(:garage).first.should == Garage.first
end
it "should create a garage and it's from the factory based watchmaker" do
- Watchmaker.construct(:car_in_garage)
+ Watchmaker.construct(:car_in_garage).map do |o|
+ o.class.to_s
+ end.should == ["Garage", "Car", "Array"]
+
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.construct(:car)
+ Watchmaker.construct(:car).first.should be_a_kind_of Car
Car.all.count.should == 1
Garage.all.count.should == 1
end
View
11 spec/spec_helper.rb
@@ -16,12 +16,17 @@
require 'watchmaker'
-require 'simplecov'
-SimpleCov.start
+if RUBY_VERSION > "1.9"
+ require 'simplecov'
+ SimpleCov.start
+end
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
-ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+ActiveRecord::Base.establish_connection(
+ :adapter => "sqlite3",
+ :database => ":memory:"
+)
ActiveRecord::Base.silence do
ActiveRecord::Migration.verbose = false
View
6 spec/support/watchmakers.rb
@@ -6,6 +6,12 @@
end
end
+Watchmaker.learn :two_cars do
+ 2.times do
+ Factory.create(:car)
+ end
+end
+
Watchmaker.learn :garage, :factories => [:garage]
Watchmaker.learn :car, :factories => [:car], :watchmakers => [:garage]

0 comments on commit f289988

Please sign in to comment.