Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tag: v0.2.0
Fetching contributors…

Cannot retrieve contributors at this time

89 lines (51 sloc) 2.22 KB


Build complex objects easily for use in integration tests.


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.


Define profiles

Implicit profiles

Specify a dependency hash of profile name to objects. The watchmaker will either yield another watchmaker or a factory when resolving those dependencies.

Watchmaker.define :lots_of_things => [:car, :garage, :boat]

Lambda-based profiles

When called, will call the lambda.

Watchmaker.define :two_garages do
  2.times do 
    Factory.create :garage

Factory-based profiles

Create a garage using the garage factory.

Watchmaker.define :garage, :factories => [:garage] do
  # Some other post-factory creation setup here.

Watchmaker-based profiles

Create a garage using the garage factory.

Watchmaker.define :garage, :factories => [:garage]

Create a car using the car factory, and a garage using the garage watchmaker.

Watchmaker.define :car, :factories => [:car], :watchmakers => [:garage]

Inject created objects into the lambda

Inject the factory-created garage and car into the block.

Watchmaker.define :car_in_garage, :factories => [:garage, :car] do |garage, car| << car

Manufacture objects

Build in-memory objects using the two garages profile. :two_garages

Build persisted objects using the two garages profile.

Watchmaker.create :two_garages

Get your objects back

Watchmaker returns the objects created.

Watchmaker.create(:garage).first.class # Garage

Inspiration for the name

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.


The watchmaker gem was written by Christopher Meiklejohn from Swipely, Inc..

Jump to Line
Something went wrong with that request. Please try again.