aub-machine 1.0.2 → 1.0.3
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 +5 -0
- data/README.textile +11 -4
- data/Rakefile +31 -42
- data/VERSION.yml +4 -0
- data/lib/machine.rb +9 -3
- data/machine.gemspec +51 -18
- data/test/machine_test.rb +30 -1
- data/test/test.db +0 -0
- metadata +20 -24
data/README.textile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
h1. machine
|
2
2
|
|
3
|
-
Machine is a factory tool designed for a fixture replacement in Rails applications. It borrows a few concepts
|
4
|
-
from "factory_girl":http://github.com/thoughtbot/factory_girl/tree/master but applies attributes to objects
|
5
|
-
differently and has a different concept for associations.
|
3
|
+
Machine is a factory tool designed for a fixture replacement in Rails applications. It borrows a few concepts from "factory_girl":http://github.com/thoughtbot/factory_girl/tree/master but applies attributes to objects differently and has a different concept for associations.
|
6
4
|
|
7
5
|
Written by "Aubrey Holland":mailto:aubreyholland@gmail.com.
|
8
6
|
|
@@ -91,6 +89,15 @@ attributes will be used in place of the default ones defined in the machine.
|
|
91
89
|
Machine(:car, :make => 'Ferrari')
|
92
90
|
</code></pre>
|
93
91
|
|
92
|
+
In addition, a block can be passed and it will be called with the newly created
|
93
|
+
object as an argument.
|
94
|
+
|
95
|
+
<pre><code>
|
96
|
+
Machine(:car) do |car|
|
97
|
+
car.make = 'Ferrari'
|
98
|
+
end
|
99
|
+
</code></pre>
|
100
|
+
|
94
101
|
h3. associations
|
95
102
|
|
96
103
|
Associations are filled using the machine object that is yielded in the block of the machine
|
@@ -155,4 +162,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
155
162
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
156
163
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
157
164
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
158
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
165
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/testtask'
|
4
|
-
|
5
|
-
|
6
|
-
require '
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = "machine"
|
9
|
+
gemspec.summary = "machine is an implementation of the factory pattern for creating model objects when testing Ruby apps"
|
10
|
+
gemspec.description = "machine is an implementation of the factory pattern for creating model objects when testing Ruby apps. It borrows concepts from factory_girl, but has a different implementation for associations."
|
11
|
+
gemspec.email = "aubreyholland@gmail.com"
|
12
|
+
gemspec.homepage = "http://github.com/aub/machine"
|
13
|
+
gemspec.authors = ["Aubrey Holland"]
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
7
18
|
|
8
19
|
desc 'Default: run unit tests.'
|
9
20
|
task :default => :test
|
@@ -15,47 +26,25 @@ Rake::TestTask.new(:test) do |t|
|
|
15
26
|
t.verbose = true
|
16
27
|
end
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
rdoc.rdoc_files.include('README.textile')
|
24
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
29
|
+
# Try to use hanna to create spiffier docs.
|
30
|
+
begin
|
31
|
+
require 'hanna/rdoctask'
|
32
|
+
rescue LoadError
|
33
|
+
require 'rake/rdoctask'
|
25
34
|
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
s.require_path = 'lib'
|
35
|
-
s.test_files = Dir[*['test/**/*_test.rb']]
|
36
|
-
|
37
|
-
s.has_rdoc = true
|
38
|
-
s.extra_rdoc_files = ["README.textile"]
|
39
|
-
s.rdoc_options = ['--line-numbers', '--inline-source', "--main", "README.textile"]
|
40
|
-
|
41
|
-
s.authors = ["Aubrey Holland"]
|
42
|
-
s.email = %q{aubrey@patch.com}
|
43
|
-
|
44
|
-
s.platform = Gem::Platform::RUBY
|
45
|
-
s.add_dependency(%q<activesupport>, [">= 1.0"])
|
46
|
-
end
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
if File.exist?('VERSION.yml')
|
38
|
+
config = YAML.load(File.read('VERSION.yml'))
|
39
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
40
|
+
else
|
41
|
+
version = ""
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "machine #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
rdoc.options << '--webcvs=http://github.com/aub/machine/tree/master/'
|
51
49
|
end
|
52
50
|
|
53
|
-
desc "Clean files generated by rake tasks"
|
54
|
-
task :clobber => [:clobber_rdoc, :clobber_package]
|
55
|
-
|
56
|
-
desc "Generate a gemspec file"
|
57
|
-
task :gemspec do
|
58
|
-
File.open("#{spec.name}.gemspec", 'w') do |f|
|
59
|
-
f.write spec.to_ruby
|
60
|
-
end
|
61
|
-
end
|
data/VERSION.yml
ADDED
data/lib/machine.rb
CHANGED
@@ -4,6 +4,12 @@ require 'machine/machine_group'
|
|
4
4
|
require 'machine/sequence'
|
5
5
|
|
6
6
|
# Shorthand method for building a machine, is an alias for Machine.build(name, attributes)
|
7
|
-
def Machine(name, attributes={})
|
8
|
-
Machine.build(name, attributes)
|
9
|
-
end
|
7
|
+
def Machine(name, attributes={}, &block)
|
8
|
+
Machine.build(name, attributes, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
# And the same drill for building a machine and saving the result.
|
12
|
+
def Machine!(name, attributes={}, &block)
|
13
|
+
Machine.build!(name, attributes, &block)
|
14
|
+
end
|
15
|
+
|
data/machine.gemspec
CHANGED
@@ -1,24 +1,57 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
|
-
s.version = '1.0.2'
|
3
|
-
s.date = %q{2008-11-07}
|
4
|
-
|
5
4
|
s.name = %q{machine}
|
6
|
-
s.
|
7
|
-
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
|
15
|
-
|
16
|
-
s.
|
17
|
-
|
18
|
-
|
19
|
-
|
5
|
+
s.version = "1.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Aubrey Holland"]
|
9
|
+
s.date = %q{2009-08-24}
|
10
|
+
s.description = %q{machine is an implementation of the factory pattern for creating model objects when testing Ruby apps. It borrows concepts from factory_girl, but has a different implementation for associations.}
|
11
|
+
s.email = %q{aubreyholland@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"README.textile"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"README.textile",
|
18
|
+
"Rakefile",
|
19
|
+
"TODO.textile",
|
20
|
+
"VERSION.yml",
|
21
|
+
"lib/machine.rb",
|
22
|
+
"lib/machine/association_helper.rb",
|
23
|
+
"lib/machine/machine.rb",
|
24
|
+
"lib/machine/machine_group.rb",
|
25
|
+
"lib/machine/sequence.rb",
|
26
|
+
"machine.gemspec",
|
27
|
+
"rails/init.rb",
|
28
|
+
"test/machine_group_test.rb",
|
29
|
+
"test/machine_test.rb",
|
30
|
+
"test/models.rb",
|
31
|
+
"test/sequence_test.rb",
|
32
|
+
"test/test.db",
|
33
|
+
"test/test_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/aub/machine}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.3}
|
39
|
+
s.summary = %q{machine is an implementation of the factory pattern for creating model objects when testing Ruby apps}
|
40
|
+
s.test_files = [
|
41
|
+
"test/machine_group_test.rb",
|
42
|
+
"test/machine_test.rb",
|
43
|
+
"test/models.rb",
|
44
|
+
"test/sequence_test.rb",
|
45
|
+
"test/test_helper.rb"
|
46
|
+
]
|
47
|
+
|
20
48
|
if s.respond_to? :specification_version then
|
21
49
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
-
s.specification_version =
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
else
|
54
|
+
end
|
55
|
+
else
|
23
56
|
end
|
24
57
|
end
|
data/test/machine_test.rb
CHANGED
@@ -193,7 +193,7 @@ class MachineTest < Test::Unit::TestCase
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
|
-
context "using the helper
|
196
|
+
context "using the helper methods" do
|
197
197
|
setup do
|
198
198
|
Machine.define :article do |article, machine|
|
199
199
|
article.title = 'aha'
|
@@ -215,6 +215,27 @@ class MachineTest < Test::Unit::TestCase
|
|
215
215
|
should "not save the object" do
|
216
216
|
assert Machine(:article).new_record?
|
217
217
|
end
|
218
|
+
|
219
|
+
should "apply Machine! correctly" do
|
220
|
+
assert Machine!(:article).instance_of?(Article)
|
221
|
+
end
|
222
|
+
|
223
|
+
should "set the attributes" do
|
224
|
+
assert_equal 'aha', Machine!(:article).title
|
225
|
+
end
|
226
|
+
|
227
|
+
should "allow replacement attributes" do
|
228
|
+
assert_equal 'ooh', Machine!(:article, :title => 'ooh').title
|
229
|
+
end
|
230
|
+
|
231
|
+
should "save the object" do
|
232
|
+
assert !Machine!(:article).new_record?
|
233
|
+
end
|
234
|
+
|
235
|
+
should "take a block to set attributes" do
|
236
|
+
assert_equal 'big fun', Machine(:article) { |obj| obj.title = 'big fun' }.title
|
237
|
+
assert_equal 'big fun', Machine!(:article) { |obj| obj.title = 'big fun' }.title
|
238
|
+
end
|
218
239
|
end
|
219
240
|
|
220
241
|
context "applying a machine to an existing object" do
|
@@ -288,5 +309,13 @@ class MachineTest < Test::Unit::TestCase
|
|
288
309
|
assert_equal 'fun', article.title
|
289
310
|
assert !article.new_record?
|
290
311
|
end
|
312
|
+
|
313
|
+
should 'use the block in the shorthand version of build' do
|
314
|
+
article = Machine(:article) do |article|
|
315
|
+
article.title = 'another one'
|
316
|
+
end
|
317
|
+
assert_equal 'another one', article.title
|
318
|
+
assert article.new_record?
|
319
|
+
end
|
291
320
|
end
|
292
321
|
end
|
data/test/test.db
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aub-machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aubrey Holland
|
8
|
-
- patch
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
|
-
date:
|
12
|
+
date: 2009-08-24 00:00:00 -07:00
|
14
13
|
default_executable:
|
15
14
|
dependencies: []
|
16
15
|
|
17
|
-
description: machine
|
18
|
-
email:
|
16
|
+
description: machine is an implementation of the factory pattern for creating model objects when testing Ruby apps. It borrows concepts from factory_girl, but has a different implementation for associations.
|
17
|
+
email: aubreyholland@gmail.com
|
19
18
|
executables: []
|
20
19
|
|
21
20
|
extensions: []
|
@@ -23,35 +22,30 @@ extensions: []
|
|
23
22
|
extra_rdoc_files:
|
24
23
|
- README.textile
|
25
24
|
files:
|
26
|
-
-
|
27
|
-
-
|
25
|
+
- .gitignore
|
26
|
+
- README.textile
|
27
|
+
- Rakefile
|
28
|
+
- TODO.textile
|
29
|
+
- VERSION.yml
|
30
|
+
- lib/machine.rb
|
28
31
|
- lib/machine/association_helper.rb
|
29
32
|
- lib/machine/machine.rb
|
30
33
|
- lib/machine/machine_group.rb
|
31
34
|
- lib/machine/sequence.rb
|
32
|
-
- lib/machine.rb
|
33
|
-
- machine-1.0.0.gem
|
34
35
|
- machine.gemspec
|
35
|
-
- rails
|
36
36
|
- rails/init.rb
|
37
|
-
- Rakefile
|
38
|
-
- README.textile
|
39
|
-
- test
|
40
37
|
- test/machine_group_test.rb
|
41
38
|
- test/machine_test.rb
|
42
39
|
- test/models.rb
|
43
40
|
- test/sequence_test.rb
|
44
41
|
- test/test.db
|
45
42
|
- test/test_helper.rb
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
has_rdoc: false
|
44
|
+
homepage: http://github.com/aub/machine
|
45
|
+
licenses:
|
49
46
|
post_install_message:
|
50
47
|
rdoc_options:
|
51
|
-
- --
|
52
|
-
- --inline-source
|
53
|
-
- --main
|
54
|
-
- README.textile
|
48
|
+
- --charset=UTF-8
|
55
49
|
require_paths:
|
56
50
|
- lib
|
57
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -69,11 +63,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
63
|
requirements: []
|
70
64
|
|
71
65
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.3.5
|
73
67
|
signing_key:
|
74
|
-
specification_version:
|
75
|
-
summary:
|
68
|
+
specification_version: 3
|
69
|
+
summary: machine is an implementation of the factory pattern for creating model objects when testing Ruby apps
|
76
70
|
test_files:
|
77
|
-
- test/machine_test.rb
|
78
71
|
- test/machine_group_test.rb
|
72
|
+
- test/machine_test.rb
|
73
|
+
- test/models.rb
|
79
74
|
- test/sequence_test.rb
|
75
|
+
- test/test_helper.rb
|