watchmaker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
6
+ spec/*.log
7
+ db/*.sqlite3
8
+ html
9
+ *.rbc
10
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@watchmaker --create
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ script: "bundle exec rake spec"
5
+ gemfile:
6
+ - gemfiles/rails-3.0.9.gemfile
7
+ - gemfiles/rails-3.1.0.rc5.gemfile
8
+ - gemfiles/rails-master.gemfile
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+
3
+ appraise "rails-master" do
4
+ gem "rails", :git => "git://github.com/rails/rails.git"
5
+ end
6
+
7
+ appraise "rails-3.1.0.rc5" do
8
+ gem "rails", "3.1.0.rc5"
9
+ end
10
+
11
+ appraise "rails-3.0.9" do
12
+ gem "rails", "3.0.9"
13
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in materializer.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { "spec/" }
7
+ watch('spec/spec_helper.rb') { "spec/" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
13
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec/" }
15
+ watch('spec/spec_helper.rb') { "spec/" }
16
+ watch('config/routes.rb') { "spec/routing" }
17
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
18
+ # Capybara request specs
19
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
20
+ end
21
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Swipely, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,85 @@
1
+ = Watchmaker
2
+
3
+ Build complex objects easily for use in integration tests.
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
+
15
+ === Basics
16
+
17
+ Watchmaker creates persisted objects only. This is because these
18
+ objects are meant for integration tests where persistence is required.
19
+
20
+ === Learn profiles
21
+
22
+ ==== Lambda-based profiles
23
+
24
+ When called, will call the lambda.
25
+
26
+ Watchmaker.learn :two_garages do
27
+ 2.times do
28
+ Factory.create :garage
29
+ end
30
+ end
31
+
32
+ ==== Factory-based profiles
33
+
34
+ Create a garage using the garage factory.
35
+
36
+ Watchmaker.learn :garage, :factories => [:garage] do
37
+ # Some other post-factory creation setup here.
38
+ end
39
+
40
+ ==== Watchmaker-based profiles
41
+
42
+ Create a garage using the garage factory.
43
+
44
+ Watchmaker.learn :garage, :factories => [:garage]
45
+
46
+ Create a car using the car factory, and a garage using the garage
47
+ watchmaker.
48
+
49
+ Watchmaker.learn :car, :factories => [:car], :watchmakers => [:garage]
50
+
51
+ ==== Inject created objects into the lambda
52
+
53
+ Inject the factory-created garage and car into the block.
54
+
55
+ Watchmaker.learn :car_in_garage, :factories => [:garage, :car] do |garage, car|
56
+ garage.cars << car
57
+ end
58
+
59
+ ==== Grab your objects
60
+
61
+ Watchmaker returns the objects created.
62
+
63
+ Watchmaker.construct(:garage).first.class # Garage
64
+
65
+ === Construct objects
66
+
67
+ Build objects using the two garages profile.
68
+
69
+ Watchmaker.construct :two_garages
70
+
71
+ Build objects using the garage profile.
72
+
73
+ Watchmaker.construct :garages
74
+
75
+ == Inspiration for the name
76
+
77
+ William Paley's {Watchmaker Analogy and Argument}[http://en.wikipedia.org/wiki/Watchmaker_analogy#The_Watchmaker_argument].
78
+
79
+ == License
80
+
81
+ Watchmaker is Copyright © 2011 Christopher Meiklejohn. It is free software, and may be redistributed under the terms specified in the LICENSE file.
82
+
83
+ == About
84
+
85
+ The watchmaker gem was written by {Christopher Meiklejohn}[mailto:cmeiklejohn@swipely.com] from {Swipely, Inc.}[http://www.swipely.com].
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+ require 'rake'
7
+ require 'rdoc/task'
8
+ require 'rubygems/package_task'
9
+ require 'rspec/core/rake_task'
10
+ require 'appraisal'
11
+
12
+ desc "Default: run the specs"
13
+ task :default => [:all]
14
+
15
+ desc 'Test the plugin under all supported Rails versions.'
16
+ task :all => ["appraisal:install"] do |t|
17
+ exec('rake appraisal spec')
18
+ end
19
+
20
+ RSpec::Core::RakeTask.new do |t|
21
+ t.pattern = 'spec/**/*_spec.rb'
22
+ end
23
+
24
+ RDoc::Task.new do |rdoc|
25
+ rdoc.main = "README.rdoc"
26
+ rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
27
+ rdoc.options << '-f' << 'horo'
28
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: UTF-8
2
+
3
+ ActiveRecord::Schema.define do
4
+ self.verbose = false
5
+
6
+ create_table :garages, :force => true do |t|
7
+ t.string :name
8
+ t.string :location
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :cars, :force => true do |t|
13
+ t.string :name
14
+ t.integer :garage_id
15
+ t.timestamps
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.0.9"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: /home/cmeiklejohn/Repositories/watchmaker
3
+ specs:
4
+ watchmaker (0.0.1)
5
+ factory_girl
6
+ factory_girl_rails
7
+ rails (~> 3.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ ZenTest (4.6.0)
13
+ abstract (1.0.0)
14
+ actionmailer (3.0.9)
15
+ actionpack (= 3.0.9)
16
+ mail (~> 2.2.19)
17
+ actionpack (3.0.9)
18
+ activemodel (= 3.0.9)
19
+ activesupport (= 3.0.9)
20
+ builder (~> 2.1.2)
21
+ erubis (~> 2.6.6)
22
+ i18n (~> 0.5.0)
23
+ rack (~> 1.2.1)
24
+ rack-mount (~> 0.6.14)
25
+ rack-test (~> 0.5.7)
26
+ tzinfo (~> 0.3.23)
27
+ activemodel (3.0.9)
28
+ activesupport (= 3.0.9)
29
+ builder (~> 2.1.2)
30
+ i18n (~> 0.5.0)
31
+ activerecord (3.0.9)
32
+ activemodel (= 3.0.9)
33
+ activesupport (= 3.0.9)
34
+ arel (~> 2.0.10)
35
+ tzinfo (~> 0.3.23)
36
+ activeresource (3.0.9)
37
+ activemodel (= 3.0.9)
38
+ activesupport (= 3.0.9)
39
+ activesupport (3.0.9)
40
+ appraisal (0.3.8)
41
+ bundler
42
+ rake
43
+ arel (2.0.10)
44
+ builder (2.1.2)
45
+ diesel (0.1.5)
46
+ railties
47
+ diff-lcs (1.1.2)
48
+ erubis (2.6.6)
49
+ abstract (>= 1.0.0)
50
+ factory_girl (2.0.3)
51
+ factory_girl_rails (1.1.0)
52
+ factory_girl (~> 2.0.0)
53
+ railties (>= 3.0.0)
54
+ guard (0.5.1)
55
+ thor (~> 0.14.6)
56
+ guard-rspec (0.4.1)
57
+ guard (>= 0.4.0)
58
+ horo (1.0.3)
59
+ rdoc (>= 2.5)
60
+ i18n (0.5.0)
61
+ mail (2.2.19)
62
+ activesupport (>= 2.3.6)
63
+ i18n (>= 0.4.0)
64
+ mime-types (~> 1.16)
65
+ treetop (~> 1.4.8)
66
+ mime-types (1.16)
67
+ mocha (0.9.12)
68
+ polyglot (0.3.2)
69
+ rack (1.2.3)
70
+ rack-mount (0.6.14)
71
+ rack (>= 1.0.0)
72
+ rack-test (0.5.7)
73
+ rack (>= 1.0)
74
+ rails (3.0.9)
75
+ actionmailer (= 3.0.9)
76
+ actionpack (= 3.0.9)
77
+ activerecord (= 3.0.9)
78
+ activeresource (= 3.0.9)
79
+ activesupport (= 3.0.9)
80
+ bundler (~> 1.0)
81
+ railties (= 3.0.9)
82
+ railties (3.0.9)
83
+ actionpack (= 3.0.9)
84
+ activesupport (= 3.0.9)
85
+ rake (>= 0.8.7)
86
+ rdoc (~> 3.4)
87
+ thor (~> 0.14.4)
88
+ rake (0.9.2)
89
+ rdoc (3.9.2)
90
+ rspec (2.6.0)
91
+ rspec-core (~> 2.6.0)
92
+ rspec-expectations (~> 2.6.0)
93
+ rspec-mocks (~> 2.6.0)
94
+ rspec-core (2.6.4)
95
+ rspec-expectations (2.6.0)
96
+ diff-lcs (~> 1.1.2)
97
+ rspec-mocks (2.6.0)
98
+ rspec-rails (2.6.1)
99
+ actionpack (~> 3.0)
100
+ activesupport (~> 3.0)
101
+ railties (~> 3.0)
102
+ rspec (~> 2.6.0)
103
+ simplecov (0.4.2)
104
+ simplecov-html (~> 0.4.4)
105
+ simplecov-html (0.4.5)
106
+ sqlite3 (1.3.4)
107
+ thor (0.14.6)
108
+ timecop (0.3.5)
109
+ treetop (1.4.10)
110
+ polyglot
111
+ polyglot (>= 0.3.1)
112
+ tzinfo (0.3.29)
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ ZenTest
119
+ appraisal (~> 0.3.5)
120
+ bundler (~> 1.0.15)
121
+ diesel
122
+ guard
123
+ guard-rspec
124
+ horo
125
+ mocha
126
+ rails (= 3.0.9)
127
+ rspec
128
+ rspec-rails
129
+ simplecov
130
+ sqlite3
131
+ timecop
132
+ watchmaker!
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.1.0.rc5"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: /home/cmeiklejohn/Repositories/watchmaker
3
+ specs:
4
+ watchmaker (0.0.1)
5
+ factory_girl
6
+ factory_girl_rails
7
+ rails (~> 3.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ ZenTest (4.6.0)
13
+ actionmailer (3.1.0.rc5)
14
+ actionpack (= 3.1.0.rc5)
15
+ mail (~> 2.3.0)
16
+ actionpack (3.1.0.rc5)
17
+ activemodel (= 3.1.0.rc5)
18
+ activesupport (= 3.1.0.rc5)
19
+ builder (~> 3.0.0)
20
+ erubis (~> 2.7.0)
21
+ i18n (~> 0.6)
22
+ rack (~> 1.3.1)
23
+ rack-cache (~> 1.0.2)
24
+ rack-mount (~> 0.8.1)
25
+ rack-test (~> 0.6.0)
26
+ sprockets (~> 2.0.0.beta.12)
27
+ activemodel (3.1.0.rc5)
28
+ activesupport (= 3.1.0.rc5)
29
+ bcrypt-ruby (~> 2.1.4)
30
+ builder (~> 3.0.0)
31
+ i18n (~> 0.6)
32
+ activerecord (3.1.0.rc5)
33
+ activemodel (= 3.1.0.rc5)
34
+ activesupport (= 3.1.0.rc5)
35
+ arel (~> 2.1.4)
36
+ tzinfo (~> 0.3.29)
37
+ activeresource (3.1.0.rc5)
38
+ activemodel (= 3.1.0.rc5)
39
+ activesupport (= 3.1.0.rc5)
40
+ activesupport (3.1.0.rc5)
41
+ multi_json (~> 1.0)
42
+ appraisal (0.3.8)
43
+ bundler
44
+ rake
45
+ arel (2.1.4)
46
+ bcrypt-ruby (2.1.4)
47
+ builder (3.0.0)
48
+ diesel (0.1.5)
49
+ railties
50
+ diff-lcs (1.1.2)
51
+ erubis (2.7.0)
52
+ factory_girl (2.0.3)
53
+ factory_girl_rails (1.1.0)
54
+ factory_girl (~> 2.0.0)
55
+ railties (>= 3.0.0)
56
+ guard (0.5.1)
57
+ thor (~> 0.14.6)
58
+ guard-rspec (0.4.1)
59
+ guard (>= 0.4.0)
60
+ hike (1.2.0)
61
+ horo (1.0.3)
62
+ rdoc (>= 2.5)
63
+ i18n (0.6.0)
64
+ mail (2.3.0)
65
+ i18n (>= 0.4.0)
66
+ mime-types (~> 1.16)
67
+ treetop (~> 1.4.8)
68
+ mime-types (1.16)
69
+ mocha (0.9.12)
70
+ multi_json (1.0.3)
71
+ polyglot (0.3.2)
72
+ rack (1.3.2)
73
+ rack-cache (1.0.2)
74
+ rack (>= 0.4)
75
+ rack-mount (0.8.2)
76
+ rack (>= 1.0.0)
77
+ rack-ssl (1.3.2)
78
+ rack
79
+ rack-test (0.6.1)
80
+ rack (>= 1.0)
81
+ rails (3.1.0.rc5)
82
+ actionmailer (= 3.1.0.rc5)
83
+ actionpack (= 3.1.0.rc5)
84
+ activerecord (= 3.1.0.rc5)
85
+ activeresource (= 3.1.0.rc5)
86
+ activesupport (= 3.1.0.rc5)
87
+ bundler (~> 1.0)
88
+ railties (= 3.1.0.rc5)
89
+ railties (3.1.0.rc5)
90
+ actionpack (= 3.1.0.rc5)
91
+ activesupport (= 3.1.0.rc5)
92
+ rack-ssl (~> 1.3.2)
93
+ rake (>= 0.8.7)
94
+ rdoc (~> 3.4)
95
+ thor (~> 0.14.6)
96
+ rake (0.9.2)
97
+ rdoc (3.9.2)
98
+ rspec (2.6.0)
99
+ rspec-core (~> 2.6.0)
100
+ rspec-expectations (~> 2.6.0)
101
+ rspec-mocks (~> 2.6.0)
102
+ rspec-core (2.6.4)
103
+ rspec-expectations (2.6.0)
104
+ diff-lcs (~> 1.1.2)
105
+ rspec-mocks (2.6.0)
106
+ rspec-rails (2.6.1)
107
+ actionpack (~> 3.0)
108
+ activesupport (~> 3.0)
109
+ railties (~> 3.0)
110
+ rspec (~> 2.6.0)
111
+ simplecov (0.4.2)
112
+ simplecov-html (~> 0.4.4)
113
+ simplecov-html (0.4.5)
114
+ sprockets (2.0.0.beta.13)
115
+ hike (~> 1.2)
116
+ rack (~> 1.0)
117
+ tilt (!= 1.3.0, ~> 1.1)
118
+ sqlite3 (1.3.4)
119
+ thor (0.14.6)
120
+ tilt (1.3.2)
121
+ timecop (0.3.5)
122
+ treetop (1.4.10)
123
+ polyglot
124
+ polyglot (>= 0.3.1)
125
+ tzinfo (0.3.29)
126
+
127
+ PLATFORMS
128
+ ruby
129
+
130
+ DEPENDENCIES
131
+ ZenTest
132
+ appraisal (~> 0.3.5)
133
+ bundler (~> 1.0.15)
134
+ diesel
135
+ guard
136
+ guard-rspec
137
+ horo
138
+ mocha
139
+ rails (= 3.1.0.rc5)
140
+ rspec
141
+ rspec-rails
142
+ simplecov
143
+ sqlite3
144
+ timecop
145
+ watchmaker!
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", :git=>"git://github.com/rails/rails.git"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,151 @@
1
+ GIT
2
+ remote: git://github.com/rails/rails.git
3
+ revision: e6fdfd0f6f80d47c97152826322ea8b01519b5c2
4
+ specs:
5
+ actionmailer (3.2.0.beta)
6
+ actionpack (= 3.2.0.beta)
7
+ mail (~> 2.3.0)
8
+ actionpack (3.2.0.beta)
9
+ activemodel (= 3.2.0.beta)
10
+ activesupport (= 3.2.0.beta)
11
+ builder (~> 3.0.0)
12
+ erubis (~> 2.7.0)
13
+ i18n (~> 0.6)
14
+ rack (~> 1.3.2)
15
+ rack-cache (~> 1.0.2)
16
+ rack-mount (~> 0.8.1)
17
+ rack-test (~> 0.6.0)
18
+ sprockets (~> 2.0.0.beta.12)
19
+ activemodel (3.2.0.beta)
20
+ activesupport (= 3.2.0.beta)
21
+ bcrypt-ruby (~> 2.1.4)
22
+ builder (~> 3.0.0)
23
+ i18n (~> 0.6)
24
+ activerecord (3.2.0.beta)
25
+ activemodel (= 3.2.0.beta)
26
+ activesupport (= 3.2.0.beta)
27
+ arel (~> 2.2.0)
28
+ tzinfo (~> 0.3.29)
29
+ activeresource (3.2.0.beta)
30
+ activemodel (= 3.2.0.beta)
31
+ activesupport (= 3.2.0.beta)
32
+ activesupport (3.2.0.beta)
33
+ i18n (~> 0.6)
34
+ multi_json (~> 1.0)
35
+ rails (3.2.0.beta)
36
+ actionmailer (= 3.2.0.beta)
37
+ actionpack (= 3.2.0.beta)
38
+ activerecord (= 3.2.0.beta)
39
+ activeresource (= 3.2.0.beta)
40
+ activesupport (= 3.2.0.beta)
41
+ bundler (~> 1.0)
42
+ railties (= 3.2.0.beta)
43
+ railties (3.2.0.beta)
44
+ actionpack (= 3.2.0.beta)
45
+ activesupport (= 3.2.0.beta)
46
+ rack-ssl (~> 1.3.2)
47
+ rake (>= 0.8.7)
48
+ rdoc (~> 3.4)
49
+ thor (~> 0.14.6)
50
+
51
+ PATH
52
+ remote: /home/cmeiklejohn/Repositories/watchmaker
53
+ specs:
54
+ watchmaker (0.0.1)
55
+ factory_girl
56
+ factory_girl_rails
57
+ rails (~> 3.0)
58
+
59
+ GEM
60
+ remote: http://rubygems.org/
61
+ specs:
62
+ ZenTest (4.6.0)
63
+ appraisal (0.3.8)
64
+ bundler
65
+ rake
66
+ arel (2.2.0)
67
+ bcrypt-ruby (2.1.4)
68
+ builder (3.0.0)
69
+ diesel (0.1.5)
70
+ railties
71
+ diff-lcs (1.1.2)
72
+ erubis (2.7.0)
73
+ factory_girl (2.0.3)
74
+ factory_girl_rails (1.1.0)
75
+ factory_girl (~> 2.0.0)
76
+ railties (>= 3.0.0)
77
+ guard (0.5.1)
78
+ thor (~> 0.14.6)
79
+ guard-rspec (0.4.1)
80
+ guard (>= 0.4.0)
81
+ hike (1.2.0)
82
+ horo (1.0.3)
83
+ rdoc (>= 2.5)
84
+ i18n (0.6.0)
85
+ mail (2.3.0)
86
+ i18n (>= 0.4.0)
87
+ mime-types (~> 1.16)
88
+ treetop (~> 1.4.8)
89
+ mime-types (1.16)
90
+ mocha (0.9.12)
91
+ multi_json (1.0.3)
92
+ polyglot (0.3.2)
93
+ rack (1.3.2)
94
+ rack-cache (1.0.2)
95
+ rack (>= 0.4)
96
+ rack-mount (0.8.2)
97
+ rack (>= 1.0.0)
98
+ rack-ssl (1.3.2)
99
+ rack
100
+ rack-test (0.6.1)
101
+ rack (>= 1.0)
102
+ rake (0.9.2)
103
+ rdoc (3.9.2)
104
+ rspec (2.6.0)
105
+ rspec-core (~> 2.6.0)
106
+ rspec-expectations (~> 2.6.0)
107
+ rspec-mocks (~> 2.6.0)
108
+ rspec-core (2.6.4)
109
+ rspec-expectations (2.6.0)
110
+ diff-lcs (~> 1.1.2)
111
+ rspec-mocks (2.6.0)
112
+ rspec-rails (2.6.1)
113
+ actionpack (~> 3.0)
114
+ activesupport (~> 3.0)
115
+ railties (~> 3.0)
116
+ rspec (~> 2.6.0)
117
+ simplecov (0.4.2)
118
+ simplecov-html (~> 0.4.4)
119
+ simplecov-html (0.4.5)
120
+ sprockets (2.0.0.beta.13)
121
+ hike (~> 1.2)
122
+ rack (~> 1.0)
123
+ tilt (!= 1.3.0, ~> 1.1)
124
+ sqlite3 (1.3.4)
125
+ thor (0.14.6)
126
+ tilt (1.3.2)
127
+ timecop (0.3.5)
128
+ treetop (1.4.10)
129
+ polyglot
130
+ polyglot (>= 0.3.1)
131
+ tzinfo (0.3.29)
132
+
133
+ PLATFORMS
134
+ ruby
135
+
136
+ DEPENDENCIES
137
+ ZenTest
138
+ appraisal (~> 0.3.5)
139
+ bundler (~> 1.0.15)
140
+ diesel
141
+ guard
142
+ guard-rspec
143
+ horo
144
+ mocha
145
+ rails!
146
+ rspec
147
+ rspec-rails
148
+ simplecov
149
+ sqlite3
150
+ timecop
151
+ watchmaker!
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+
3
+ module Watchmaker # :nodoc:
4
+ VERSION = "0.0.1"
5
+ end
data/lib/watchmaker.rb ADDED
@@ -0,0 +1,76 @@
1
+ # encoding: UTF-8
2
+
3
+ require "watchmaker/version"
4
+
5
+ module Watchmaker # :nodoc:
6
+
7
+ # Attribute accessors to hold profile mappings.
8
+ #
9
+ mattr_accessor :profiles
10
+
11
+ # Learn a new profile.
12
+ #
13
+ def self.learn(profile, options = {}, &block)
14
+
15
+ # Initialize the profiles unless they exist.
16
+ #
17
+ @@profiles = {} unless @@profiles
18
+
19
+ # Add the block to the list of known profiles.
20
+ #
21
+ @@profiles[profile] = {
22
+ :options => options,
23
+ :block => block
24
+ }
25
+
26
+ end
27
+
28
+ # Contruct a profile based on lambda.
29
+ #
30
+ def self.construct(profile)
31
+
32
+ # Store created objects.
33
+ #
34
+ objects = []
35
+
36
+ # If a profile exists, call the proc we've stored; if not, raise.
37
+ #
38
+ if selected_profile = @@profiles[profile]
39
+
40
+ if options = selected_profile[:options]
41
+
42
+ # For any supplied factories, create them.
43
+ #
44
+ if factories = options[:factories]
45
+ factories.each do |factory|
46
+ objects << Factory.create(factory.to_sym)
47
+ end
48
+ end
49
+
50
+ # For any supplied watchmakers, create them.
51
+ #
52
+ if watchmakers = options[:watchmakers]
53
+ watchmakers.each do |watchmaker|
54
+ objects << Watchmaker.construct(watchmaker.to_sym)
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ # Run the supplied block.
61
+ #
62
+ if block = selected_profile.delete(:block)
63
+ objects << block.call(objects)
64
+ end
65
+
66
+ # Return objects.
67
+ #
68
+ objects
69
+
70
+ else
71
+ raise "#{profile} is not a valid profile"
72
+ end
73
+
74
+ end
75
+
76
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+
3
+ test:
4
+ adapter: sqlite3
5
+ database: db/test.sqlite3
6
+ pool: 5
7
+ timeout: 5000
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Garage do
6
+ it "should create some garages from the lambda based watchmaker" do
7
+ Watchmaker.construct(:two_garages)
8
+ Garage.all.count.should == 2
9
+ end
10
+
11
+ it "should create a garage from the factory based watchmaker" do
12
+ Watchmaker.construct(:garage)
13
+ Garage.all.count.should == 1
14
+ end
15
+
16
+ it "return the objects created from a watchmaker" do
17
+ Watchmaker.construct(:garage).first.should be_a_kind_of Garage
18
+ Garage.all.count.should == 1
19
+ end
20
+
21
+ it "should create a garage and it's from the factory based watchmaker" do
22
+ Watchmaker.construct(:car_in_garage)
23
+ Car.all.count.should == 1
24
+ Garage.all.count.should == 1
25
+ Garage.first.cars.should include(Car.first)
26
+ end
27
+
28
+ it "should create a car from the watchmaker based watchmaker" do
29
+ Watchmaker.construct(:car)
30
+ Car.all.count.should == 1
31
+ Garage.all.count.should == 1
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ ENV["RAILS_ENV"] ||= "test"
4
+
5
+ PROJECT_ROOT = File.expand_path("../..", __FILE__)
6
+ $LOAD_PATH << File.join(PROJECT_ROOT, "lib")
7
+
8
+ require 'rails/all'
9
+ require 'rails/test_help'
10
+ Bundler.require
11
+
12
+ require 'diesel/testing'
13
+ require 'rspec/rails'
14
+
15
+ require 'factory_girl_rails'
16
+ require 'timecop'
17
+
18
+ require 'watchmaker'
19
+
20
+ require 'simplecov'
21
+ SimpleCov.start
22
+
23
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
24
+
25
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
26
+
27
+ ActiveRecord::Base.silence do
28
+ ActiveRecord::Migration.verbose = false
29
+
30
+ load(File.dirname(__FILE__) + '/../db/schema.rb')
31
+ end
32
+
33
+ RSpec.configure do |config|
34
+ config.use_transactional_fixtures = true
35
+ config.backtrace_clean_patterns << %r{gems/}
36
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ Factory.define :garage do |garage|
6
+ garage.sequence(:name) { |n| "name-#{n}" }
7
+ garage.sequence(:location) { |n| "location-#{n}" }
8
+ end
9
+
10
+ Factory.define :car do |car|
11
+ car.sequence(:name) { |n| "name-#{n}" }
12
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: UTF-8
2
+
3
+ class Garage < ActiveRecord::Base
4
+ has_many :cars
5
+ end
6
+
7
+ class Car < ActiveRecord::Base
8
+ belongs_to :garage
9
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ Watchmaker.learn :two_garages do
4
+ 2.times do
5
+ Factory.create(:garage)
6
+ end
7
+ end
8
+
9
+ Watchmaker.learn :garage, :factories => [:garage]
10
+
11
+ Watchmaker.learn :car, :factories => [:car], :watchmakers => [:garage]
12
+
13
+ Watchmaker.learn :car_in_garage, :factories => [:garage, :car] do |garage, car|
14
+ garage.cars << car
15
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: UTF-8
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "watchmaker/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "watchmaker"
8
+ s.version = Watchmaker::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Christopher Meiklejohn"]
11
+ s.email = ["christopher.meiklejohn@gmail.com"]
12
+ s.homepage = "https://github.com/cmeiklejohn/watchmaker"
13
+ s.summary = %q{Build complex objects easily for use in integration tests.}
14
+ s.description = %q{Build complex objects easily for use in integration tests.}
15
+
16
+ s.rubyforge_project = "watchmaker"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency('rails', '~> 3.0')
24
+ s.add_dependency('factory_girl')
25
+ s.add_dependency('factory_girl_rails')
26
+
27
+ s.add_development_dependency('bundler', '~> 1.0.15')
28
+ s.add_development_dependency('rspec')
29
+ s.add_development_dependency('rspec-rails')
30
+ s.add_development_dependency('sqlite3')
31
+ s.add_development_dependency('mocha')
32
+ s.add_development_dependency('appraisal', '~> 0.3.5')
33
+ s.add_development_dependency('timecop')
34
+ s.add_development_dependency('horo')
35
+ s.add_development_dependency('simplecov')
36
+ s.add_development_dependency('diesel')
37
+ s.add_development_dependency('ZenTest')
38
+ s.add_development_dependency('guard')
39
+ s.add_development_dependency('guard-rspec')
40
+ end
metadata ADDED
@@ -0,0 +1,255 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watchmaker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Meiklejohn
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-11 00:00:00.000000000 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &17963700 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *17963700
26
+ - !ruby/object:Gem::Dependency
27
+ name: factory_girl
28
+ requirement: &17963120 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *17963120
37
+ - !ruby/object:Gem::Dependency
38
+ name: factory_girl_rails
39
+ requirement: &17935800 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *17935800
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &17933900 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.15
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *17933900
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: &17932280 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *17932280
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec-rails
72
+ requirement: &17931100 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *17931100
81
+ - !ruby/object:Gem::Dependency
82
+ name: sqlite3
83
+ requirement: &17929280 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *17929280
92
+ - !ruby/object:Gem::Dependency
93
+ name: mocha
94
+ requirement: &17907180 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *17907180
103
+ - !ruby/object:Gem::Dependency
104
+ name: appraisal
105
+ requirement: &17906380 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.3.5
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: *17906380
114
+ - !ruby/object:Gem::Dependency
115
+ name: timecop
116
+ requirement: &17905660 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: *17905660
125
+ - !ruby/object:Gem::Dependency
126
+ name: horo
127
+ requirement: &17904840 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: *17904840
136
+ - !ruby/object:Gem::Dependency
137
+ name: simplecov
138
+ requirement: &17903660 !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: *17903660
147
+ - !ruby/object:Gem::Dependency
148
+ name: diesel
149
+ requirement: &17902220 !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ type: :development
156
+ prerelease: false
157
+ version_requirements: *17902220
158
+ - !ruby/object:Gem::Dependency
159
+ name: ZenTest
160
+ requirement: &17901160 !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: *17901160
169
+ - !ruby/object:Gem::Dependency
170
+ name: guard
171
+ requirement: &17900380 !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: *17900380
180
+ - !ruby/object:Gem::Dependency
181
+ name: guard-rspec
182
+ requirement: &17877800 !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: *17877800
191
+ description: Build complex objects easily for use in integration tests.
192
+ email:
193
+ - christopher.meiklejohn@gmail.com
194
+ executables: []
195
+ extensions: []
196
+ extra_rdoc_files: []
197
+ files:
198
+ - .gitignore
199
+ - .rspec
200
+ - .rvmrc
201
+ - .travis.yml
202
+ - Appraisals
203
+ - Gemfile
204
+ - Guardfile
205
+ - LICENSE
206
+ - README.rdoc
207
+ - Rakefile
208
+ - db/schema.rb
209
+ - gemfiles/rails-3.0.9.gemfile
210
+ - gemfiles/rails-3.0.9.gemfile.lock
211
+ - gemfiles/rails-3.1.0.rc5.gemfile
212
+ - gemfiles/rails-3.1.0.rc5.gemfile.lock
213
+ - gemfiles/rails-master.gemfile
214
+ - gemfiles/rails-master.gemfile.lock
215
+ - lib/watchmaker.rb
216
+ - lib/watchmaker/version.rb
217
+ - spec/database.yml
218
+ - spec/models/garage_spec.rb
219
+ - spec/spec_helper.rb
220
+ - spec/support/factories.rb
221
+ - spec/support/models.rb
222
+ - spec/support/watchmakers.rb
223
+ - watchmaker.gemspec
224
+ has_rdoc: true
225
+ homepage: https://github.com/cmeiklejohn/watchmaker
226
+ licenses: []
227
+ post_install_message:
228
+ rdoc_options: []
229
+ require_paths:
230
+ - lib
231
+ required_ruby_version: !ruby/object:Gem::Requirement
232
+ none: false
233
+ requirements:
234
+ - - ! '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ segments:
238
+ - 0
239
+ hash: 2836815950547273425
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ none: false
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ segments:
247
+ - 0
248
+ hash: 2836815950547273425
249
+ requirements: []
250
+ rubyforge_project: watchmaker
251
+ rubygems_version: 1.6.2
252
+ signing_key:
253
+ specification_version: 3
254
+ summary: Build complex objects easily for use in integration tests.
255
+ test_files: []