Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a generator for Shoulda

  • Loading branch information...
commit 3a49194e79c391bc6aff949a224e9b695845919a 1 parent f629bef
averyj authored
18 Manifest.txt
@@ -101,6 +101,11 @@ rubygems_generators/install_rspec/templates/spec.rb
101 101 rubygems_generators/install_rspec/templates/spec/spec.opts
102 102 rubygems_generators/install_rspec/templates/spec/spec_helper.rb
103 103 rubygems_generators/install_rspec/templates/tasks/rspec.rake
  104 +rubygems_generators/install_shoulda/USAGE
  105 +rubygems_generators/install_shoulda/install_shoulda_generator.rb
  106 +rubygems_generators/install_shoulda/templates/spec.rb
  107 +rubygems_generators/install_shoulda/templates/spec/spec_helper.rb
  108 +rubygems_generators/install_shoulda/templates/tasks/shoulda.rake
104 109 rubygems_generators/install_test_unit/USAGE
105 110 rubygems_generators/install_test_unit/install_test_unit_generator.rb
106 111 rubygems_generators/install_test_unit/templates/test/test.rb
@@ -129,16 +134,3 @@ test/test_newgem_generator.rb
129 134 test/test_newgem_simple_generator.rb
130 135 test/test_plain_theme_generator.rb
131 136 test/test_rubyforge.rb
132   -website/images/beginning-ruby.jpg
133   -website/index.html
134   -website/index.txt
135   -website/javascripts/rounded_corners_lite.inc.js
136   -website/rubyforge.html
137   -website/rubyforge.txt
138   -website/stylesheets/screen.css
139   -website/template.html.erb
140   -website/template.js
141   -website/version-raw.js
142   -website/version-raw.txt
143   -website/version.js
144   -website/version.txt
2  app_generators/newgem/newgem_generator.rb
@@ -60,6 +60,8 @@ def manifest
60 60 m.dependency "install_test_unit", [gem_name], :destination => destination_root, :collision => :force
61 61 when "rspec"
62 62 m.dependency "install_rspec", [gem_name], :destination => destination_root, :collision => :force
  63 + when "shoulda"
  64 + m.dependency "install_shoulda", [gem_name], :destination => destination_root, :collision => :force
63 65 end
64 66
65 67 # Website
5 rubygems_generators/install_shoulda/USAGE
... ... @@ -0,0 +1,5 @@
  1 +Description:
  2 +
  3 +
  4 +Usage:
  5 +
56 rubygems_generators/install_shoulda/install_shoulda_generator.rb
... ... @@ -0,0 +1,56 @@
  1 +
  2 +class InstallShouldaGenerator < RubiGen::Base
  3 +
  4 + default_options :author => nil
  5 +
  6 + attr_reader :gem_name, :module_name
  7 +
  8 + def initialize(runtime_args, runtime_options = {})
  9 + super
  10 + @destination_root = File.expand_path(destination_root)
  11 + @gem_name = base_name
  12 + @module_name = @gem_name.camelcase
  13 + extract_options
  14 + end
  15 +
  16 + def manifest
  17 + record do |m|
  18 + # Ensure appropriate folder(s) exists
  19 + m.directory 'spec'
  20 + m.directory 'tasks'
  21 +
  22 + m.template 'spec.rb', "spec/#{gem_name}_spec.rb"
  23 + m.template "spec/spec_helper.rb", "spec/spec_helper.rb"
  24 +
  25 + m.file_copy_each %w( shoulda.rake ), 'tasks'
  26 + end
  27 + end
  28 +
  29 + protected
  30 + def banner
  31 + <<-EOS
  32 +Install Shoulda testing support.
  33 +
  34 +Includes a rake task (tasks/shoulda.rake) to be loaded by the root Rakefile,
  35 +which provides a "test" task.
  36 +
  37 +EOS
  38 + end
  39 +
  40 + def add_options!(opts)
  41 + # opts.separator ''
  42 + # opts.separator 'Options:'
  43 + # For each option below, place the default
  44 + # at the top of the file next to "default_options"
  45 + # opts.on("-a", "--author=\"Your Name\"", String,
  46 + # "Some comment about this option",
  47 + # "Default: none") { |x| options[:author] = x }
  48 + end
  49 +
  50 + def extract_options
  51 + # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
  52 + # Templates can access these value via the attr_reader-generated methods, but not the
  53 + # raw instance variable value.
  54 + # @author = options[:author]
  55 + end
  56 +end
13 rubygems_generators/install_shoulda/templates/spec.rb
... ... @@ -0,0 +1,13 @@
  1 +require File.dirname(__FILE__) + '/spec_helper.rb'
  2 +
  3 +class <%= gem_name.capitalize! %>Spec < Test::Unit::TestCase
  4 + context "A <%= gem_name %> instance" do
  5 + setup do
  6 +
  7 + end
  8 +
  9 + should "run" do
  10 + raise "write your specs!"
  11 + end
  12 + end
  13 +end
10 rubygems_generators/install_shoulda/templates/spec/spec_helper.rb
... ... @@ -0,0 +1,10 @@
  1 +begin
  2 + require 'spec'
  3 +rescue LoadError
  4 + require 'rubygems'
  5 + gem 'Shoulda'
  6 + require 'Shoulda'
  7 +end
  8 +
  9 +$:.unshift(File.dirname(__FILE__) + '/../lib')
  10 +require '<%= gem_name %>'
15 rubygems_generators/install_shoulda/templates/tasks/shoulda.rake
... ... @@ -0,0 +1,15 @@
  1 +begin
  2 + require 'shoulda'
  3 +rescue LoadError
  4 + require 'rubygems'
  5 + require 'shoulda'
  6 +end
  7 +
  8 +require 'rake/testtask'
  9 +
  10 +desc "Run the shoulda test under /spec"
  11 +Rake::TestTask.new do |t|
  12 + t.libs << "test"
  13 + t.test_files = FileList['spec/*_spec.rb']
  14 + t.verbose = true
  15 +end

0 comments on commit 3a49194

Please sign in to comment.
Something went wrong with that request. Please try again.