Permalink
Browse files

Added a generator for Shoulda

  • Loading branch information...
1 parent f629bef commit 3a49194e79c391bc6aff949a224e9b695845919a @averyj committed Jan 2, 2009
View
18 Manifest.txt
@@ -101,6 +101,11 @@ rubygems_generators/install_rspec/templates/spec.rb
rubygems_generators/install_rspec/templates/spec/spec.opts
rubygems_generators/install_rspec/templates/spec/spec_helper.rb
rubygems_generators/install_rspec/templates/tasks/rspec.rake
+rubygems_generators/install_shoulda/USAGE
+rubygems_generators/install_shoulda/install_shoulda_generator.rb
+rubygems_generators/install_shoulda/templates/spec.rb
+rubygems_generators/install_shoulda/templates/spec/spec_helper.rb
+rubygems_generators/install_shoulda/templates/tasks/shoulda.rake
rubygems_generators/install_test_unit/USAGE
rubygems_generators/install_test_unit/install_test_unit_generator.rb
rubygems_generators/install_test_unit/templates/test/test.rb
@@ -129,16 +134,3 @@ test/test_newgem_generator.rb
test/test_newgem_simple_generator.rb
test/test_plain_theme_generator.rb
test/test_rubyforge.rb
-website/images/beginning-ruby.jpg
-website/index.html
-website/index.txt
-website/javascripts/rounded_corners_lite.inc.js
-website/rubyforge.html
-website/rubyforge.txt
-website/stylesheets/screen.css
-website/template.html.erb
-website/template.js
-website/version-raw.js
-website/version-raw.txt
-website/version.js
-website/version.txt
View
2 app_generators/newgem/newgem_generator.rb
@@ -60,6 +60,8 @@ def manifest
m.dependency "install_test_unit", [gem_name], :destination => destination_root, :collision => :force
when "rspec"
m.dependency "install_rspec", [gem_name], :destination => destination_root, :collision => :force
+ when "shoulda"
+ m.dependency "install_shoulda", [gem_name], :destination => destination_root, :collision => :force
end
# Website
View
5 rubygems_generators/install_shoulda/USAGE
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
View
56 rubygems_generators/install_shoulda/install_shoulda_generator.rb
@@ -0,0 +1,56 @@
+
+class InstallShouldaGenerator < RubiGen::Base
+
+ default_options :author => nil
+
+ attr_reader :gem_name, :module_name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ @destination_root = File.expand_path(destination_root)
+ @gem_name = base_name
+ @module_name = @gem_name.camelcase
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory 'spec'
+ m.directory 'tasks'
+
+ m.template 'spec.rb', "spec/#{gem_name}_spec.rb"
+ m.template "spec/spec_helper.rb", "spec/spec_helper.rb"
+
+ m.file_copy_each %w( shoulda.rake ), 'tasks'
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Install Shoulda testing support.
+
+Includes a rake task (tasks/shoulda.rake) to be loaded by the root Rakefile,
+which provides a "test" task.
+
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |x| options[:author] = x }
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
View
13 rubygems_generators/install_shoulda/templates/spec.rb
@@ -0,0 +1,13 @@
+require File.dirname(__FILE__) + '/spec_helper.rb'
+
+class <%= gem_name.capitalize! %>Spec < Test::Unit::TestCase
+ context "A <%= gem_name %> instance" do
+ setup do
+
+ end
+
+ should "run" do
+ raise "write your specs!"
+ end
+ end
+end
View
10 rubygems_generators/install_shoulda/templates/spec/spec_helper.rb
@@ -0,0 +1,10 @@
+begin
+ require 'spec'
+rescue LoadError
+ require 'rubygems'
+ gem 'Shoulda'
+ require 'Shoulda'
+end
+
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+require '<%= gem_name %>'
View
15 rubygems_generators/install_shoulda/templates/tasks/shoulda.rake
@@ -0,0 +1,15 @@
+begin
+ require 'shoulda'
+rescue LoadError
+ require 'rubygems'
+ require 'shoulda'
+end
+
+require 'rake/testtask'
+
+desc "Run the shoulda test under /spec"
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['spec/*_spec.rb']
+ t.verbose = true
+end

0 comments on commit 3a49194

Please sign in to comment.