Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (49 sloc) 2.294 kb
23501da @cmeiklejohn Pull out link as it's not working right in rdoc.
authored
1 = Watchmaker
4dc3b4e @cmeiklejohn Initial commit.
authored
2
5c5bd3b @cmeiklejohn Noop to test bundling of new gem.
authored
3 Extract test setup and factory instantiation into reusable objects.
4dc3b4e @cmeiklejohn Initial commit.
authored
4
5 == Motivation
6
7 Extract complex setup code for integration tests out into a central
8 place; for example:
9
10 * Share setup code between cucumber and test/unit by centralizing it.
11 * Run this code in the console in development mode to seed your db with test data.
12
13 == Using
14
f34e3d0 @cmeiklejohn Update documentation.
authored
15 === Define profiles
4dc3b4e @cmeiklejohn Initial commit.
authored
16
7cfe62a @cmeiklejohn Update readme.
authored
17 Specify car, garage and boat as a dependency for lots of things. Watchmaker
18 will either use a watchmaker by that name to fulfill that dependency, or fall
19 back to the factory if it doesn't exist.
c51a04f @cmeiklejohn New syntax type, much cleaner interface.
authored
20
f34e3d0 @cmeiklejohn Update documentation.
authored
21 Watchmaker.define :lots_of_things => [:car, :garage, :boat]
c51a04f @cmeiklejohn New syntax type, much cleaner interface.
authored
22
7cfe62a @cmeiklejohn Update readme.
authored
23 Specify a block with things to do do:
4dc3b4e @cmeiklejohn Initial commit.
authored
24
f34e3d0 @cmeiklejohn Update documentation.
authored
25 Watchmaker.define :two_garages do
4dc3b4e @cmeiklejohn Initial commit.
authored
26 2.times do
27 Factory.create :garage
28 end
29 end
30
7cfe62a @cmeiklejohn Update readme.
authored
31 Specify a factory as a dependency:
4dc3b4e @cmeiklejohn Initial commit.
authored
32
f34e3d0 @cmeiklejohn Update documentation.
authored
33 Watchmaker.define :garage, :factories => [:garage] do
4dc3b4e @cmeiklejohn Initial commit.
authored
34 # Some other post-factory creation setup here.
35 end
36
7cfe62a @cmeiklejohn Update readme.
authored
37 Specify multiple factories as dependencies:
4dc3b4e @cmeiklejohn Initial commit.
authored
38
7cfe62a @cmeiklejohn Update readme.
authored
39 Watchmaker.define :garages, :factories => [:garage, :garage] do
40 # Some other post-factory creation setup here.
41 end
4dc3b4e @cmeiklejohn Initial commit.
authored
42
7cfe62a @cmeiklejohn Update readme.
authored
43 Pass those objects in to the block:
4dc3b4e @cmeiklejohn Initial commit.
authored
44
7cfe62a @cmeiklejohn Update readme.
authored
45 Watchmaker.define :car_and_driver, :factories => [:garage, :car] do |garage, car|
46 garage.cars << car
47 end
4dc3b4e @cmeiklejohn Initial commit.
authored
48
7cfe62a @cmeiklejohn Update readme.
authored
49 Sepcify another watchmaker as a dependency:
4dc3b4e @cmeiklejohn Initial commit.
authored
50
7cfe62a @cmeiklejohn Update readme.
authored
51 Watchmaker.define :car, :watchmakers => [:garage]
4dc3b4e @cmeiklejohn Initial commit.
authored
52
7cfe62a @cmeiklejohn Update readme.
authored
53 Specify a factory and a watchmaker as a dependency:
57ed63f @cmeiklejohn Update readme and make it a bit cleaner.
authored
54
7cfe62a @cmeiklejohn Update readme.
authored
55 Watchmaker.define :car, :factories => [:car], :watchmakers => [:garage]
4dc3b4e @cmeiklejohn Initial commit.
authored
56
f34e3d0 @cmeiklejohn Update documentation.
authored
57 === Manufacture objects
4dc3b4e @cmeiklejohn Initial commit.
authored
58
f34e3d0 @cmeiklejohn Update documentation.
authored
59 Build in-memory objects using the two garages profile.
4dc3b4e @cmeiklejohn Initial commit.
authored
60
f34e3d0 @cmeiklejohn Update documentation.
authored
61 Watchmaker.build :two_garages
4dc3b4e @cmeiklejohn Initial commit.
authored
62
f34e3d0 @cmeiklejohn Update documentation.
authored
63 Build persisted objects using the two garages profile.
4dc3b4e @cmeiklejohn Initial commit.
authored
64
f34e3d0 @cmeiklejohn Update documentation.
authored
65 Watchmaker.create :two_garages
57ed63f @cmeiklejohn Update readme and make it a bit cleaner.
authored
66
f34e3d0 @cmeiklejohn Update documentation.
authored
67 ==== Get your objects back
4dc3b4e @cmeiklejohn Initial commit.
authored
68
f34e3d0 @cmeiklejohn Update documentation.
authored
69 Watchmaker returns the objects created.
57ed63f @cmeiklejohn Update readme and make it a bit cleaner.
authored
70
f34e3d0 @cmeiklejohn Update documentation.
authored
71 Watchmaker.create(:garage).first.class # Garage
4dc3b4e @cmeiklejohn Initial commit.
authored
72
57ed63f @cmeiklejohn Update readme and make it a bit cleaner.
authored
73 == Inspiration for the name
74
75 William Paley's {Watchmaker Analogy and Argument}[http://en.wikipedia.org/wiki/Watchmaker_analogy#The_Watchmaker_argument].
76
4dc3b4e @cmeiklejohn Initial commit.
authored
77 == License
78
79 Watchmaker is Copyright © 2011 Christopher Meiklejohn. It is free software, and may be redistributed under the terms specified in the LICENSE file.
80
81 == About
82
83 The watchmaker gem was written by {Christopher Meiklejohn}[mailto:cmeiklejohn@swipely.com] from {Swipely, Inc.}[http://www.swipely.com].
Something went wrong with that request. Please try again.