notahat-machinist 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/machinist.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_record'
3
+ require 'sham'
3
4
 
4
5
  module Machinist
5
6
  def self.with_save_nerfed
@@ -77,12 +78,7 @@ module Machinist
77
78
  end
78
79
  end
79
80
 
80
- if Module.const_defined?("RAILS_ENV") && RAILS_ENV == 'test'
81
- require 'sham'
82
-
83
- class ActiveRecord::Base
84
- include Machinist::ActiveRecordExtensions
85
- end
81
+ class ActiveRecord::Base
82
+ include Machinist::ActiveRecordExtensions
86
83
  end
87
84
 
88
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notahat-machinist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Yandell
@@ -9,40 +9,26 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-01 00:00:00 -08:00
12
+ date: 2008-10-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Fixtures aren't fun. Machinist is.
17
- email: pete@notahat.com
16
+ description:
17
+ email: pete@nothat.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files:
23
- - lib/machinist.rb
24
- - lib/sham.rb
25
- - README.markdown
22
+ extra_rdoc_files: []
23
+
26
24
  files:
27
- - init.rb
28
25
  - lib/machinist.rb
29
26
  - lib/sham.rb
30
- - Manifest
31
- - MIT-LICENSE
32
- - rails/init.rb
33
- - Rakefile
34
- - README.markdown
35
- - machinist.gemspec
36
27
  has_rdoc: false
37
28
  homepage: http://github.com/notahat/machinist
38
29
  post_install_message:
39
- rdoc_options:
40
- - --line-numbers
41
- - --inline-source
42
- - --title
43
- - Machinist
44
- - --main
45
- - README.markdown
30
+ rdoc_options: []
31
+
46
32
  require_paths:
47
33
  - lib
48
34
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -55,11 +41,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
41
  requirements:
56
42
  - - ">="
57
43
  - !ruby/object:Gem::Version
58
- version: "1.2"
44
+ version: "0"
59
45
  version:
60
46
  requirements: []
61
47
 
62
- rubyforge_project: machinist
48
+ rubyforge_project:
63
49
  rubygems_version: 1.2.0
64
50
  signing_key:
65
51
  specification_version: 2
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2008 Peter Yandell
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown DELETED
@@ -1,201 +0,0 @@
1
- Machinist
2
- =========
3
-
4
- *Fixtures aren't fun. Machinist is.*
5
-
6
- Machinist lets you construct test data on the fly, but instead of doing this:
7
-
8
- describe Comment do
9
- before do
10
- @user = User.create!(:name => "Test User")
11
- @post = Post.create!(:title => "Test Post", :author => @user, :body => "Lorem ipsum...")
12
- @comment = Comment.create!(
13
- :post => @post, :author_name => "Test Commenter", :author_email => "commenter@example.com",
14
- :spam => true
15
- )
16
- end
17
-
18
- it "should not include comments marked as spam in the without_spam named scope" do
19
- Comment.without_spam.should_not include(@comment)
20
- end
21
- end
22
-
23
- you can just do this:
24
-
25
- describe Comment do
26
- before do
27
- @comment = Comment.make(:spam => true)
28
- end
29
-
30
- it "should not include comments marked as spam in the without_spam named scope" do
31
- Comment.without_spam.should_not include(@comment)
32
- end
33
- end
34
-
35
- Machinist generates data for the fields you don't care about, and constructs any necessary associated objects.
36
-
37
- You tell Machinist how to do this with blueprints:
38
-
39
- require 'faker'
40
-
41
- Sham.name { Faker::Name.name }
42
- Sham.email { Faker::Internet.email }
43
- Sham.title { Faker::Lorem.sentence }
44
- Sham.body { Faker::Lorem.paragraph }
45
-
46
- User.blueprint do
47
- name { Sham.name }
48
- end
49
-
50
- Post.blueprint do
51
- title { Sham.title }
52
- author { User.make }
53
- body { Sham.body }
54
- end
55
-
56
- Comment.blueprint do
57
- post
58
- author_name { Sham.name }
59
- author_email { Sham.email }
60
- body { Sham.body }
61
- end
62
-
63
-
64
- Installation
65
- ------------
66
-
67
- Install the plugin:
68
-
69
- ./script/plugin install git://github.com/notahat/machinist.git
70
-
71
- Create a blueprints.rb in your test (or spec) directory, and require it in your test\_helper.rb (or spec\_helper.rb):
72
-
73
- require File.expand_path(File.dirname(__FILE__) + "/blueprints")
74
-
75
- Set Sham to reset before each test. In the `class Test::Unit::TestCase` block in your test\_helper.rb, add:
76
-
77
- setup { Sham.reset }
78
-
79
- or, if you're on RSpec, in the `Spec::Runner.configure` block in your spec\_helper.rb, add:
80
-
81
- config.before(:each) { Sham.reset }
82
-
83
-
84
- Sham - Generating Attribute Values
85
- ----------------------------------
86
-
87
- Sham lets you generate random but repeatable unique attributes values.
88
-
89
- For example, you could define a way to generate random names as:
90
-
91
- Sham.name { (1..10).map { ('a'..'z').to_a.rand } }
92
-
93
- Then, to generate a name, call:
94
-
95
- Sham.name
96
-
97
- So why not just define a method? Sham ensures two things for you:
98
-
99
- 1. You get the same sequence of values each time your test is run
100
- 2. You don't get any duplicate values
101
-
102
- Sham works very well with the excellent [Faker gem](http://faker.rubyforge.org/) by Benjamin Curtis. Using this, a much nicer way to generate names is:
103
-
104
- Sham.name { Faker::Name.name }
105
-
106
- Sham also supports generating numbered sequences if you prefer.
107
-
108
- Sham.name {|index| "Name #{index}" }
109
-
110
- If you want to allow duplicate values for a sham, you can pass the `:unique` option:
111
-
112
- Sham.coin_toss(:unique => false) { rand(2) == 0 ? 'heads' : 'tails' }
113
-
114
-
115
- Blueprints - Generating ActiveRecord Objects
116
- --------------------------------------------
117
-
118
- A blueprint describes how to build a generic object for an ActiveRecord model. The idea is that you let the blueprint take care of constructing all the objects and attributes that you don't care about in your test, leaving you to focus on the just the things that you're testing.
119
-
120
- A simple blueprint might look like this:
121
-
122
- Comment.blueprint do
123
- body "A comment!"
124
- end
125
-
126
- Once that's defined, you can construct a comment from this blueprint with:
127
-
128
- Comment.make
129
-
130
- Machinist calls `save!` on your ActiveRecord model to create the comment, so it will throw an exception if the blueprint doesn't pass your validations. It also calls `reload` after the `save!`.
131
-
132
- You can override values defined in the blueprint by passing parameters to make:
133
-
134
- Comment.make(:body => "A different comment!")
135
-
136
- Rather than providing a constant value for an attribute, you can use Sham to generate a value for each new object:
137
-
138
- Sham.body { Faker::Lorem.paragraph }
139
- Comment.blueprint do
140
- body { Sham.body }
141
- end
142
-
143
- Notice the curly braces around `Sham.body`. If you call `Comment.make` with your own body attribute, this block will not be executed.
144
-
145
- You can use this same syntax to generate associated objects:
146
-
147
- Comment.blueprint do
148
- post { Post.make }
149
- end
150
-
151
- If the associated model has the same name as the field, you can abbreviate this to:
152
-
153
- Comment.blueprint do
154
- post
155
- end
156
-
157
- You can refer to already assigned attributes when constructing a new attribute:
158
-
159
- Comment.blueprint do
160
- post
161
- body { "Comment on " + post.name }
162
- end
163
-
164
- You can also override associated objects when calling make:
165
-
166
- post = Post.make
167
- 3.times { Comment.make(:post => post) }
168
-
169
- It's common to need to construct an object with particular attributes, or a particular object graph, in a number of tests. The best way to abstract out the construction is to put something like this in your blueprints.rb:
170
-
171
- class Post
172
- def self.make_with_comments(attributes = {})
173
- Post.make(attributes) do |post|
174
- 3.times { Comment.make(:post => post) }
175
- end
176
- end
177
- end
178
-
179
- Note that make can take a block, into which it will pass the newly constructed object.
180
-
181
- If you want to generate an object graph without saving to the database, use make\_unsaved:
182
-
183
- Comment.make_unsaved
184
-
185
- This will generate both the Comment and the associated Post without saving either.
186
-
187
-
188
- Credits
189
- -------
190
-
191
- Written by [Pete Yandell](http://notahat.com/).
192
-
193
- Contributors:
194
-
195
- - [Roland Swingler](http://github.com/knaveofdiamonds)
196
-
197
- Thanks to Thoughtbot's [Factory Girl](http://github.com/thoughtbot/factory_girl/tree/master). Machinist was written because I loved the idea behind Factory Girl, but I thought the philosophy wasn't quite right, and I hated the syntax.
198
-
199
- ---
200
-
201
- Copyright (c) 2008 Peter Yandell, released under the MIT license
data/Rakefile DELETED
@@ -1,24 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'rake/clean'
4
- require 'spec/rake/spectask'
5
- require 'echoe'
6
-
7
- desc 'Default: run specs.'
8
- task :default => :spec
9
-
10
- desc 'Run all the specs for the machinist plugin.'
11
- Spec::Rake::SpecTask.new do |t|
12
- t.spec_files = FileList['spec/**/*_spec.rb']
13
- t.rcov = false
14
- end
15
-
16
- Echoe.new('machinist', '0.1.1') do |p|
17
- p.description = "Fixtures aren't fun. Machinist is."
18
- p.url = "http://github.com/notahat/machinist"
19
- p.author = "Pete Yandell"
20
- p.email = "pete@notahat.com"
21
- p.ignore_pattern = ["coverage/*", "pkg/**/*", "spec/*"]
22
- p.has_rdoc = false
23
- p.development_dependencies = []
24
- end
data/init.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'active_record'
2
-
3
- if RAILS_ENV == 'test'
4
- require 'machinist'
5
- require 'sham'
6
-
7
- class ActiveRecord::Base
8
- include Machinist::ActiveRecordExtensions
9
- end
10
- end
data/machinist.gemspec DELETED
@@ -1,30 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{machinist}
5
- s.version = "0.1.1"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Pete Yandell"]
9
- s.date = %q{2008-12-01}
10
- s.description = %q{Fixtures aren't fun. Machinist is.}
11
- s.email = %q{pete@notahat.com}
12
- s.extra_rdoc_files = ["lib/machinist.rb", "lib/sham.rb", "README.markdown"]
13
- s.files = ["init.rb", "lib/machinist.rb", "lib/sham.rb", "Manifest", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README.markdown", "machinist.gemspec"]
14
- s.homepage = %q{http://github.com/notahat/machinist}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Machinist", "--main", "README.markdown"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{machinist}
18
- s.rubygems_version = %q{1.3.1}
19
- s.summary = %q{Fixtures aren't fun. Machinist is.}
20
-
21
- if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
- s.specification_version = 2
24
-
25
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
- else
27
- end
28
- else
29
- end
30
- end
data/rails/init.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'active_record'
2
-
3
- if RAILS_ENV == 'test'
4
- require 'machinist'
5
- require 'sham'
6
-
7
- class ActiveRecord::Base
8
- include Machinist::ActiveRecordExtensions
9
- end
10
- end