Extract test setup and factory instantiation into reusable objects.
Extract complex setup code for integration tests out into a central place; for example:
Share setup code between cucumber and test/unit by centralizing it.
Run this code in the console in development mode to seed your db with test data.
Specify car, garage and boat as a dependency for lots of things. Watchmaker will either use a watchmaker by that name to fulfill that dependency, or fall back to the factory if it doesn't exist.
Watchmaker.define :lots_of_things => [:car, :garage, :boat]
Specify a block with things to do do:
Watchmaker.define :two_garages do 2.times do Factory.create :garage end end
Specify a factory as a dependency:
Watchmaker.define :garage, :factories => [:garage] do # Some other post-factory creation setup here. end
Specify multiple factories as dependencies:
Watchmaker.define :garages, :factories => [:garage, :garage] do # Some other post-factory creation setup here. end
Pass those objects in to the block:
Watchmaker.define :car_and_driver, :factories => [:garage, :car] do |garage, car| garage.cars << car end
Sepcify another watchmaker as a dependency:
Watchmaker.define :car, :watchmakers => [:garage]
Specify a factory and a watchmaker as a dependency:
Watchmaker.define :car, :factories => [:car], :watchmakers => [:garage]
Build in-memory objects using the two garages profile.
Build persisted objects using the two garages profile.
Watchmaker returns the objects created.
Watchmaker.create(:garage).first.class # Garage
William Paley's Watchmaker Analogy and Argument.
Watchmaker is Copyright © 2011 Christopher Meiklejohn. It is free software, and may be redistributed under the terms specified in the LICENSE file.