53cr-shoulda_generator 0.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Josh Nichols
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/Manifest ADDED
@@ -0,0 +1,32 @@
1
+ rails_generators/shoulda_model/shoulda_model_generator.rb
2
+ rails_generators/shoulda_model/templates/factory.rb
3
+ rails_generators/shoulda_model/templates/fixtures.yml
4
+ rails_generators/shoulda_model/templates/migration.rb
5
+ rails_generators/shoulda_model/templates/model.rb
6
+ rails_generators/shoulda_model/templates/unit_test.rb
7
+ rails_generators/shoulda_model/USAGE
8
+ rails_generators/shoulda_scaffold/shoulda_scaffold_generator.rb
9
+ rails_generators/shoulda_scaffold/templates/blueprint/ie.css
10
+ rails_generators/shoulda_scaffold/templates/blueprint/print.css
11
+ rails_generators/shoulda_scaffold/templates/blueprint/screen.css
12
+ rails_generators/shoulda_scaffold/templates/controller.rb
13
+ rails_generators/shoulda_scaffold/templates/erb/_form.html.erb
14
+ rails_generators/shoulda_scaffold/templates/erb/edit.html.erb
15
+ rails_generators/shoulda_scaffold/templates/erb/index.html.erb
16
+ rails_generators/shoulda_scaffold/templates/erb/layout.html.erb
17
+ rails_generators/shoulda_scaffold/templates/erb/new.html.erb
18
+ rails_generators/shoulda_scaffold/templates/erb/show.html.erb
19
+ rails_generators/shoulda_scaffold/templates/functional_test/basic.rb
20
+ rails_generators/shoulda_scaffold/templates/functional_test/should_be_restful.rb
21
+ rails_generators/shoulda_scaffold/templates/haml/_form.html.haml
22
+ rails_generators/shoulda_scaffold/templates/haml/edit.html.haml
23
+ rails_generators/shoulda_scaffold/templates/haml/index.html.haml
24
+ rails_generators/shoulda_scaffold/templates/haml/layout.html.haml
25
+ rails_generators/shoulda_scaffold/templates/haml/new.html.haml
26
+ rails_generators/shoulda_scaffold/templates/haml/show.html.haml
27
+ rails_generators/shoulda_scaffold/templates/helper.rb
28
+ rails_generators/shoulda_scaffold/USAGE
29
+ Rakefile
30
+ README.markdown
31
+ shoulda_generator.gemspec
32
+ Manifest
data/README.markdown ADDED
@@ -0,0 +1,79 @@
1
+ # Shoulda generators
2
+
3
+ One night at a Boston Ruby hackfest, I finally got sick of using the Rails default generators, and then having to twiddle them to meet my needs and tastes. This includes using things like:
4
+
5
+ * [shoulda](http://thoughtbot.com/projects/shoulda)
6
+ * [factory\_girl](http://github.com/thoughtbot/factory_girl)
7
+ * [haml](http://haml.hamptoncatlin.com/)
8
+ * [blueprint](http://code.google.com/p/blueprintcss/)
9
+
10
+ The next morning, I was struck awake at 5am with the inspiration to start implementing it. shoulda\_generator is the result of this effort.
11
+
12
+ ## What you get
13
+
14
+ ### shoulda\_model
15
+
16
+ * A new model
17
+ * A migration for the model
18
+ * Skip using --skip-migration
19
+ * A factory defined with [factory_girl](http://github.com/thoughtbot/factory_girl)
20
+ * Skip using --skip-factory
21
+ * A [shoulda](http://thoughtbot.com/projects/shoulda) unit test with a few simple 'should's
22
+
23
+ #### Prereqs:
24
+
25
+ * [shoulda](http://thoughtbot.com/projects/shoulda) installed as a plugin
26
+ * [factory\_girl](http://github.com/thoughtbot/factory_girl) gem installed
27
+ * [factory\_girl\_on\_rails](http://github.com/technicalpickles/factory_girl_on_rails) installed as a plugin
28
+
29
+ ### shoulda\_scaffold
30
+
31
+ * Everything included in shoulda_model
32
+ * A controller (sans unnecessary comments)
33
+ * Choice of [haml](http://haml.hamptoncatlin.com/) (default) or ERB
34
+ * Specify which with the --templating option
35
+ * Simple layout styled with blueprint
36
+ * Skip using --skip-layout
37
+ * A helper
38
+ * A shoulda functional test using factory_girl factory, using should\_be\_restful or not
39
+ * Specify with --functional-test-style, accepts basic and should\_be\_restful
40
+
41
+ #### Prereqs:
42
+
43
+ * [shoulda](http://thoughtbot.com/projects/shoulda) installed as a plugin
44
+ * [factory\_girl](http://github.com/thoughtbot/factory_girl) gem installed
45
+ * [factory\_girl\_on\_rails](http://github.com/technicalpickles/factory_girl_on_rails) installed as a plugin
46
+ * [haml](http://haml.hamptoncatlin.com/) gem installed on the system, and the project has been hamlified using `haml --rails`
47
+
48
+ ## Getting it
49
+
50
+ shoulda\_generator is available as a gem via [GitHub](http://github.com). If you haven't done so already, you need to setup GitHub as a gem source:
51
+
52
+ $ gem sources -a http://gems.github.com
53
+
54
+ Now you can install it:
55
+
56
+ $ sudo gem install technicalpickles-shoulda_generator
57
+
58
+ ## Example usage
59
+
60
+ Usage is the same as the default Rails generators.
61
+
62
+ $ script/generate shoulda_model post title:string body:text published:boolean
63
+ $ script/generate shoulda_scaffold post title:string body:text published:boolean
64
+
65
+
66
+ ## Configuring it
67
+
68
+ You can override the default values for templating and functional\_test\_style by placing a .shoulda\_generator file in your home directory.
69
+
70
+ Here's an example `.shoulda_generator`:
71
+
72
+ :templating: erb # supported options: haml|erb
73
+ :functional_test_syle: basic # supported options: should_be_restful|basic
74
+
75
+ ## Developing it
76
+
77
+ Source is hosted on GitHub: [http://github.com/technicalpickles/shoulda_generator/tree/master](http://github.com/technicalpickles/shoulda_generator/tree/master)
78
+
79
+ You can do the usual fork/commit cycle until you have something ready to share. Send pull requests my way.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler.gemspec = Gem::Specification.new do |s|
7
+ s.name = "shoulda_generator"
8
+ s.summary = "Generators which create tests using shoulda"
9
+ s.email = "josh@technicalpickles.com"
10
+ s.homepage = "http://github.com/technicalpickles/shoulda_generator"
11
+ s.description = "Generators which create tests using shoulda"
12
+ s.authors = ["Josh Nichols"]
13
+ s.files = FileList["[A-Z]*", "{generators,lib,test}/**/*"]
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
18
+
19
+ Rake::TestTask.new do |t|
20
+ t.libs << 'lib'
21
+ t.pattern = 'test/**/*_test.rb'
22
+ t.verbose = false
23
+ end
24
+
25
+ desc 'Test by default'
26
+ task :default => :test
data/TODO ADDED
@@ -0,0 +1,8 @@
1
+ * When installing, there's an warning:
2
+
3
+ Successfully installed shoulda_generator-0.2.0
4
+ 1 gem installed
5
+ Installing ri documentation for shoulda_generator-0.2.0...
6
+ File not found: lib
7
+
8
+ * Support using resource_controller?
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ patch: 0
3
+ major: 0
4
+ minor: 2
@@ -0,0 +1 @@
1
+ # an empty YAML file - any content in here seems to get parsed as a string
@@ -0,0 +1 @@
1
+ # intentionally empty
@@ -0,0 +1 @@
1
+ # intentionally empty
@@ -0,0 +1,2 @@
1
+ module Zoo::ReptileHouse
2
+ end
@@ -0,0 +1,3 @@
1
+ class Zoo
2
+ include ReptileHouse
3
+ end
@@ -0,0 +1 @@
1
+ $initialize_test_set_from_env = 'success'
@@ -0,0 +1,2 @@
1
+ class WorkingGenerator < Rails::Generator::NamedBase
2
+ end
@@ -0,0 +1,4 @@
1
+ class AGenerator < Rails::Generator::Base
2
+ def manifest
3
+ end
4
+ end
@@ -0,0 +1 @@
1
+ raise 'This init.rb should not be evaluated because rails/init.rb exists'
@@ -0,0 +1,2 @@
1
+ module Gemlike
2
+ end
@@ -0,0 +1,7 @@
1
+ # I have access to my directory and the Rails config.
2
+ raise 'directory expected but undefined in init.rb' unless defined? directory
3
+ raise 'config expected but undefined in init.rb' unless defined? config
4
+
5
+ # My lib/ dir must be in the load path.
6
+ require 'gemlike'
7
+ raise 'missing mixin from my lib/ dir' unless defined? Gemlike
@@ -0,0 +1,2 @@
1
+ author: Plugin Author
2
+ version: 1.0.0
@@ -0,0 +1,4 @@
1
+ class StubbyGenerator < Rails::Generator::Base
2
+ def manifest
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ # I have access to my directory and the Rails config.
2
+ raise 'directory expected but undefined in init.rb' unless defined? directory
3
+ raise 'config expected but undefined in init.rb' unless defined? config
4
+
5
+ # My lib/ dir must be in the load path.
6
+ require 'stubby_mixin'
7
+ raise 'missing mixin from my lib/ dir' unless defined? StubbyMixin
@@ -0,0 +1,2 @@
1
+ module StubbyMixin
2
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+
4
+ class ShouldaModelGeneratorTest < GeneratorTestCase
5
+
6
+ def setup
7
+ Rails::Generator::Base.stubs(:sources).returns([Rails::Generator::PathSource.new(:shoulda_generator, File.join(File.dirname(__FILE__), "..", "..", "rails_generators"))])
8
+ end
9
+ context "running the default generator" do
10
+ setup do
11
+ run_generator('shoulda_model', %w(Product name:string supplier_id:integer created_at:timestamp))
12
+ end
13
+
14
+ should_generate_model :product
15
+ should_generate_factory :product
16
+ should_generate_unit_test :product
17
+ should_generate_migration :create_products
18
+
19
+ should "generate migration" do
20
+ assert_generated_migration :create_products do |t|
21
+ assert_generated_column t, :name, :string
22
+ assert_generated_column t, :supplier_id, :integer
23
+ assert_generated_column t, :created_at, :timestamp
24
+ end
25
+ end
26
+ end
27
+
28
+ context "running the generator, when skipping factory and migration" do
29
+ setup do
30
+ run_generator('shoulda_model', %w(Product name:string supplier_id:integer created_at:timestamp --skip-factory))
31
+ end
32
+
33
+ should_generate_model :product
34
+ should_not_generate_factory :product
35
+ should_generate_unit_test :product
36
+ should_generate_migration :create_products
37
+
38
+ should "not generate migration" do
39
+ assert_skipped_migration :create_products
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,36 @@
1
+ class Test::Unit::TestCase
2
+ class << self
3
+ def should_generate_model(model)
4
+ should "generate #{model} model" do
5
+ assert_generated_model_for(model) do |body|
6
+ yield body if block_given?
7
+ end
8
+ end
9
+ end
10
+
11
+ def should_generate_factory(model)
12
+ should "generate #{model} factory" do
13
+ assert_generated_factory_for(model)
14
+ end
15
+ end
16
+
17
+ def should_generate_unit_test(model)
18
+ should "generate #{model} unit test" do
19
+ assert_generated_unit_test_for(model)
20
+ end
21
+ end
22
+
23
+ def should_generate_migration(migration)
24
+ should "generate a #{migration} migration" do
25
+ assert_generated_migration migration
26
+ end
27
+ end
28
+
29
+ def should_not_generate_factory(model)
30
+ should "not generate #{model} factory" do
31
+ deny_generated_factory_for(:product)
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,288 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+
4
+ # Mock out what we need from AR::Base
5
+ module ActiveRecord
6
+ class Base
7
+ class << self
8
+ attr_accessor :pluralize_table_names, :timestamped_migrations
9
+ end
10
+ self.pluralize_table_names = true
11
+ self.timestamped_migrations = true
12
+ end
13
+
14
+ module ConnectionAdapters
15
+ class Column
16
+ attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
17
+
18
+ def initialize(name, default, sql_type = nil)
19
+ @name = name
20
+ @default = default
21
+ @type = @sql_type = sql_type
22
+ end
23
+
24
+ def human_name
25
+ @name.humanize
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ # Mock up necessities from ActionView
32
+ module ActionView
33
+ module Helpers
34
+ module ActionRecordHelper; end
35
+ class InstanceTag; end
36
+ end
37
+ end
38
+
39
+ # Set RAILS_ROOT appropriately fixture generation
40
+ tmp_dir = "#{File.dirname(__FILE__)}/fixtures/tmp"
41
+
42
+ if defined? RAILS_ROOT
43
+ RAILS_ROOT.replace tmp_dir
44
+ else
45
+ RAILS_ROOT = tmp_dir
46
+ end
47
+ FileUtils.mkdir_p RAILS_ROOT
48
+
49
+ # $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
50
+ require 'initializer'
51
+
52
+ # Mocks out the configuration
53
+ module Rails
54
+ def self.configuration
55
+ Rails::Configuration.new
56
+ end
57
+ end
58
+
59
+ require 'rails_generator'
60
+
61
+ class GeneratorTestCase < Test::Unit::TestCase
62
+ include FileUtils
63
+
64
+ def setup
65
+ ActiveRecord::Base.pluralize_table_names = true
66
+
67
+ mkdir_p "#{RAILS_ROOT}/app/views/layouts"
68
+ mkdir_p "#{RAILS_ROOT}/config"
69
+ mkdir_p "#{RAILS_ROOT}/db"
70
+ mkdir_p "#{RAILS_ROOT}/test/fixtures"
71
+ mkdir_p "#{RAILS_ROOT}/public/stylesheets"
72
+
73
+ File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f|
74
+ f << "ActionController::Routing::Routes.draw do |map|\n\nend"
75
+ end
76
+ end
77
+
78
+ def teardown
79
+ rm_rf "#{RAILS_ROOT}/app"
80
+ rm_rf "#{RAILS_ROOT}/test"
81
+ rm_rf "#{RAILS_ROOT}/config"
82
+ rm_rf "#{RAILS_ROOT}/db"
83
+ rm_rf "#{RAILS_ROOT}/public"
84
+ end
85
+
86
+ def test_truth
87
+ # don't complain, test/unit
88
+ end
89
+
90
+ # Instantiates the Generator.
91
+ def build_generator(name, params)
92
+ Rails::Generator::Base.instance(name, params)
93
+ end
94
+
95
+ # Runs the +create+ command (like the command line does).
96
+ def run_generator(name, params)
97
+ silence_generator do
98
+ build_generator(name, params).command(:create).invoke!
99
+ end
100
+ end
101
+
102
+ # Silences the logger temporarily and returns the output as a String.
103
+ def silence_generator
104
+ logger_original = Rails::Generator::Base.logger
105
+ myout = StringIO.new
106
+ Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(myout)
107
+ yield if block_given?
108
+ Rails::Generator::Base.logger = logger_original
109
+ myout.string
110
+ end
111
+
112
+ # Asserts that the given controller was generated.
113
+ # It takes a name or symbol without the <tt>_controller</tt> part and an optional super class.
114
+ # The contents of the class source file is passed to a block.
115
+ def assert_generated_controller_for(name, parent = "ApplicationController")
116
+ assert_generated_class "app/controllers/#{name.to_s.underscore}_controller", parent do |body|
117
+ yield body if block_given?
118
+ end
119
+ end
120
+
121
+ # Asserts that the given model was generated.
122
+ # It takes a name or symbol and an optional super class.
123
+ # The contents of the class source file is passed to a block.
124
+ def assert_generated_model_for(name, parent = "ActiveRecord::Base")
125
+ assert_generated_class "app/models/#{name.to_s.underscore}", parent do |body|
126
+ yield body if block_given?
127
+ end
128
+ end
129
+
130
+ # Asserts that the given helper was generated.
131
+ # It takes a name or symbol without the <tt>_helper</tt> part.
132
+ # The contents of the module source file is passed to a block.
133
+ def assert_generated_helper_for(name)
134
+ assert_generated_module "app/helpers/#{name.to_s.underscore}_helper" do |body|
135
+ yield body if block_given?
136
+ end
137
+ end
138
+
139
+ # Asserts that the given functional test was generated.
140
+ # It takes a name or symbol without the <tt>_controller_test</tt> part and an optional super class.
141
+ # The contents of the class source file is passed to a block.
142
+ def assert_generated_functional_test_for(name, parent = "ActionController::TestCase")
143
+ assert_generated_class "test/functional/#{name.to_s.underscore}_controller_test",parent do |body|
144
+ yield body if block_given?
145
+ end
146
+ end
147
+
148
+ # Asserts that the given unit test was generated.
149
+ # It takes a name or symbol without the <tt>_test</tt> part and an optional super class.
150
+ # The contents of the class source file is passed to a block.
151
+ def assert_generated_unit_test_for(name, parent = "ActiveSupport::TestCase")
152
+ assert_generated_class "test/unit/#{name.to_s.underscore}_test", parent do |body|
153
+ yield body if block_given?
154
+ end
155
+ end
156
+
157
+ # Asserts that the given file was generated.
158
+ # The contents of the file is passed to a block.
159
+ def assert_generated_file(path)
160
+ assert_file_exists(path)
161
+ File.open("#{RAILS_ROOT}/#{path}") do |f|
162
+ yield f.read if block_given?
163
+ end
164
+ end
165
+
166
+ # asserts that the given file exists
167
+ def assert_file_exists(path)
168
+ assert File.exist?("#{RAILS_ROOT}/#{path}"),
169
+ "The file '#{RAILS_ROOT}/#{path}' should exist"
170
+ end
171
+
172
+ # Asserts that the given class source file was generated.
173
+ # It takes a path without the <tt>.rb</tt> part and an optional super class.
174
+ # The contents of the class source file is passed to a block.
175
+ def assert_generated_class(path, parent = nil)
176
+ # FIXME: Sucky way to detect namespaced classes
177
+ if path.split('/').size > 3
178
+ path =~ /\/?(\d+_)?(\w+)\/(\w+)$/
179
+ class_name = "#{$2.camelize}::#{$3.camelize}"
180
+ else
181
+ path =~ /\/?(\d+_)?(\w+)$/
182
+ class_name = $2.camelize
183
+ end
184
+
185
+ assert_generated_file("#{path}.rb") do |body|
186
+ assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class"
187
+ yield body if block_given?
188
+ end
189
+ end
190
+
191
+ # Asserts that the given module source file was generated.
192
+ # It takes a path without the <tt>.rb</tt> part.
193
+ # The contents of the class source file is passed to a block.
194
+ def assert_generated_module(path)
195
+ # FIXME: Sucky way to detect namespaced modules
196
+ if path.split('/').size > 3
197
+ path =~ /\/?(\w+)\/(\w+)$/
198
+ module_name = "#{$1.camelize}::#{$2.camelize}"
199
+ else
200
+ path =~ /\/?(\w+)$/
201
+ module_name = $1.camelize
202
+ end
203
+
204
+ assert_generated_file("#{path}.rb") do |body|
205
+ assert_match /module #{module_name}/, body, "the file '#{path}.rb' should be a module"
206
+ yield body if block_given?
207
+ end
208
+ end
209
+
210
+ # Asserts that the given CSS stylesheet file was generated.
211
+ # It takes a path without the <tt>.css</tt> part.
212
+ # The contents of the stylesheet source file is passed to a block.
213
+ def assert_generated_stylesheet(path)
214
+ assert_generated_file("public/stylesheets/#{path}.css") do |body|
215
+ yield body if block_given?
216
+ end
217
+ end
218
+
219
+ # Asserts that the given YAML file was generated.
220
+ # It takes a path without the <tt>.yml</tt> part.
221
+ # The parsed YAML tree is passed to a block.
222
+ def assert_generated_yaml(path)
223
+ assert_generated_file("#{path}.yml") do |body|
224
+ yaml = YAML.load(body)
225
+ assert yaml, 'YAML data missing'
226
+ yield yaml if block_given?
227
+ end
228
+ end
229
+
230
+ # Asserts that the given fixtures YAML file was generated.
231
+ # It takes a fixture name without the <tt>.yml</tt> part.
232
+ # The parsed YAML tree is passed to a block.
233
+ def assert_generated_fixtures_for(name)
234
+ assert_generated_yaml "test/fixtures/#{name.to_s.underscore}" do |yaml|
235
+ yield yaml if block_given?
236
+ end
237
+ end
238
+
239
+ # Asserts that the given views were generated.
240
+ # It takes a controller name and a list of views (including extensions).
241
+ # The body of each view is passed to a block.
242
+ def assert_generated_views_for(name, *actions)
243
+ actions.each do |action|
244
+ assert_generated_file("app/views/#{name.to_s.underscore}/#{action}") do |body|
245
+ yield body if block_given?
246
+ end
247
+ end
248
+ end
249
+
250
+ def assert_generated_migration(name, parent = "ActiveRecord::Migration")
251
+ file = Dir.glob("#{RAILS_ROOT}/db/migrate/*_#{name.to_s.underscore}.rb").first
252
+ file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s
253
+ assert_generated_class file, parent do |body|
254
+ assert_match /timestamps/, body, "should have timestamps defined"
255
+ yield body if block_given?
256
+ end
257
+ end
258
+
259
+ # Asserts that the given migration file was not generated.
260
+ # It takes the name of the migration as a parameter.
261
+ def assert_skipped_migration(name)
262
+ migration_file = "#{RAILS_ROOT}/db/migrate/001_#{name.to_s.underscore}.rb"
263
+ assert !File.exist?(migration_file), "should not create migration #{migration_file}"
264
+ end
265
+
266
+ # Asserts that the given resource was added to the routes.
267
+ def assert_added_route_for(name)
268
+ assert_generated_file("config/routes.rb") do |body|
269
+ assert_match /map.resources :#{name.to_s.underscore}/, body,
270
+ "should add route for :#{name.to_s.underscore}"
271
+ end
272
+ end
273
+
274
+ # Asserts that the given methods are defined in the body.
275
+ # This does assume standard rails code conventions with regards to the source code.
276
+ # The body of each individual method is passed to a block.
277
+ def assert_has_method(body, *methods)
278
+ methods.each do |name|
279
+ assert body =~ /^ def #{name}(\(.+\))?\n((\n| .*\n)*) end/, "should have method #{name}"
280
+ yield(name, $2) if block_given?
281
+ end
282
+ end
283
+
284
+ # Asserts that the given column is defined in the migration.
285
+ def assert_generated_column(body, name, type)
286
+ assert_match /t\.#{type.to_s} :#{name.to_s}/, body, "should have column #{name.to_s} defined"
287
+ end
288
+ end
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ gem 'ruby-debug'
3
+ require 'ruby-debug'
4
+ gem 'activesupport'
5
+ require 'active_support'
6
+ gem 'activerecord'
7
+ require 'active_record'
8
+ gem 'actionpack'
9
+ require 'action_controller'
10
+ require 'action_view'
11
+ gem 'rails'
12
+
13
+ gem 'thoughtbot-shoulda'
14
+ require 'shoulda'
15
+
16
+ gem 'mocha'
17
+ require 'mocha'
18
+
19
+ require File.join(File.dirname(__FILE__), 'shoulda_macros', 'generator_macros')
20
+
21
+ require 'active_support/core_ext/test'
22
+
23
+
24
+ require File.join(File.dirname(__FILE__), 'stolen_from_railties')
25
+
26
+ unless defined?(RAILS_DEFAULT_LOGGER)
27
+ @test_log = File.join(RAILS_ROOT, 'test.log')
28
+ RAILS_DEFAULT_LOGGER = Logger.new(@test_log)
29
+ end
30
+
31
+ class GeneratorTestCase
32
+ # Asserts that the given factory was created.
33
+ def assert_generated_factory_for(name)
34
+ assert_generated_file "test/factories/#{name.to_s.underscore}_factory.rb"
35
+ end
36
+
37
+ # Asserts that the given factory was NOT created.
38
+ def deny_generated_factory_for(name)
39
+ deny_file_exists "test/factories/#{name.to_s.underscore}_factory.rb"
40
+ end
41
+
42
+ # asserts that the given file DOES NOT exists
43
+ def deny_file_exists(path)
44
+ assert ! File.exist?("#{RAILS_ROOT}/#{path}"),
45
+ "The file '#{RAILS_ROOT}/#{path}' should not exist"
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 53cr-shoulda_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Nichols
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Generators which create tests using shoulda
17
+ email: josh@technicalpickles.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - Manifest
27
+ - Rakefile
28
+ - README.markdown
29
+ - TODO
30
+ - VERSION.yml
31
+ - test/fixtures
32
+ - test/fixtures/about_yml_plugins
33
+ - test/fixtures/about_yml_plugins/bad_about_yml
34
+ - test/fixtures/about_yml_plugins/bad_about_yml/about.yml
35
+ - test/fixtures/about_yml_plugins/bad_about_yml/init.rb
36
+ - test/fixtures/about_yml_plugins/plugin_without_about_yml
37
+ - test/fixtures/about_yml_plugins/plugin_without_about_yml/init.rb
38
+ - test/fixtures/eager
39
+ - test/fixtures/eager/zoo
40
+ - test/fixtures/eager/zoo/reptile_house.rb
41
+ - test/fixtures/eager/zoo.rb
42
+ - test/fixtures/environment_with_constant.rb
43
+ - test/fixtures/lib
44
+ - test/fixtures/lib/generators
45
+ - test/fixtures/lib/generators/missing_class
46
+ - test/fixtures/lib/generators/missing_class/missing_class_generator.rb
47
+ - test/fixtures/lib/generators/missing_class/templates
48
+ - test/fixtures/lib/generators/missing_generator
49
+ - test/fixtures/lib/generators/missing_generator/templates
50
+ - test/fixtures/lib/generators/missing_templates
51
+ - test/fixtures/lib/generators/working
52
+ - test/fixtures/lib/generators/working/working_generator.rb
53
+ - test/fixtures/plugins
54
+ - test/fixtures/plugins/alternate
55
+ - test/fixtures/plugins/alternate/a
56
+ - test/fixtures/plugins/alternate/a/generators
57
+ - test/fixtures/plugins/alternate/a/generators/a_generator
58
+ - test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb
59
+ - test/fixtures/plugins/alternate/a/lib
60
+ - test/fixtures/plugins/default
61
+ - test/fixtures/plugins/default/acts
62
+ - test/fixtures/plugins/default/acts/acts_as_chunky_bacon
63
+ - test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib
64
+ - test/fixtures/plugins/default/empty
65
+ - test/fixtures/plugins/default/gemlike
66
+ - test/fixtures/plugins/default/gemlike/init.rb
67
+ - test/fixtures/plugins/default/gemlike/lib
68
+ - test/fixtures/plugins/default/gemlike/lib/gemlike.rb
69
+ - test/fixtures/plugins/default/gemlike/rails
70
+ - test/fixtures/plugins/default/gemlike/rails/init.rb
71
+ - test/fixtures/plugins/default/plugin_with_no_lib_dir
72
+ - test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb
73
+ - test/fixtures/plugins/default/stubby
74
+ - test/fixtures/plugins/default/stubby/about.yml
75
+ - test/fixtures/plugins/default/stubby/generators
76
+ - test/fixtures/plugins/default/stubby/generators/stubby_generator
77
+ - test/fixtures/plugins/default/stubby/generators/stubby_generator/stubby_generator.rb
78
+ - test/fixtures/plugins/default/stubby/init.rb
79
+ - test/fixtures/plugins/default/stubby/lib
80
+ - test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb
81
+ - test/fixtures/tmp
82
+ - test/fixtures/tmp/test.log
83
+ - test/rails_generators
84
+ - test/rails_generators/shoulda_model_generator_test.rb
85
+ - test/shoulda_macros
86
+ - test/shoulda_macros/generator_macros.rb
87
+ - test/stolen_from_railties.rb
88
+ - test/test_helper.rb
89
+ has_rdoc: false
90
+ homepage: http://github.com/53cr/shoulda_generator
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.2.0
112
+ signing_key:
113
+ specification_version: 2
114
+ summary: Generators which create tests using shoulda
115
+ test_files: []
116
+