Permalink
Browse files

0.2.0 - Enable minitest and mocha by default

  • Loading branch information...
1 parent 63355d1 commit c1c50c41bbd6362f0b174eb5a57073e3f8b63d9c @txus txus committed Apr 4, 2011
View
18 Readme.md
@@ -23,6 +23,24 @@ The `my_blogpost.markdown` file should be a regular markdown file with some head
# My awesome header
## More markdown goodness, etc.
+##Gem component
+
+To bootstrap a new gem, type this:
+
+ $ gram gem create my_gem
+
+By default, the new gem will be using Minitest & Mocha. If you prefer RSpec:
+
+ $ gram gem create my_gem --rspec
+
+And if you want to create a Rails extension or anything requiring ActiveRecord,
+just use the `--rails` option:
+
+ $ gram gem create my_gem --rails
+
+This will add the required dependencies and enable the test suite to use
+ActiveRecord with in-memory sqlite :)
+
## Copyright
Copyright (c) 2011 Codegram. See LICENSE for details.
View
26 lib/gram/gem/generator.rb
@@ -11,13 +11,19 @@ class Generator < Thor
no_tasks do
def generate(name, options)
@rails = true if options.include?("--rails")
+ @rspec = true if options.include?("--rspec")
+
@underscored = name.underscore
@camelized = name.camelize
run "bundle gem #{@underscored}"
remove_file("#{@underscored}/Rakefile")
- template('templates/Rakefile.tt', "#{@underscored}/Rakefile")
+ if rspec
+ template('templates/Rakefile_rspec.tt', "#{@underscored}/Rakefile")
+ else
+ template('templates/Rakefile.tt', "#{@underscored}/Rakefile")
+ end
remove_file("#{@underscored}/.gitignore")
template('templates/gitignore.tt', "#{@underscored}/.gitignore")
@@ -26,16 +32,26 @@ def generate(name, options)
template('templates/rvmrc.tt', "#{@underscored}/.rvmrc")
empty_directory "#{@underscored}/spec"
- template('templates/spec/spec_helper.tt', "#{@underscored}/spec/spec_helper.rb")
+
+ if rspec
+ template('templates/spec/rspec_helper.tt', "#{@underscored}/spec/spec_helper.rb")
+ else
+ template('templates/spec/minispec_helper.tt', "#{@underscored}/spec/spec_helper.rb")
+ end
inject_into_file "#{@underscored}/#{@underscored}.gemspec", :after => "s.rubyforge_project = \"#{@underscored}\"" do
runtime_dependencies = []
runtime_dependencies << " s.add_runtime_dependency 'activerecord', '~> 3.0.5'" if rails
development_dependencies = []
development_dependencies << " s.add_runtime_dependency 'sqlite3'" if rails
+ if rspec
+ development_dependencies << " s.add_development_dependency 'rspec', '~> 2.5.0'"
+ else
+ development_dependencies << " s.add_development_dependency 'minitest'"
+ end
+ development_dependencies << " s.add_development_dependency 'mocha'" unless rspec
development_dependencies += [
- " s.add_development_dependency 'rspec', '~> 2.5.0'",
" s.add_development_dependency 'yard'",
" s.add_development_dependency 'bluecloth'" ]
@@ -57,6 +73,10 @@ def camelized
def rails
@rails
end
+
+ def rspec
+ @rspec
+ end
end
end
end
View
10 lib/gram/gem/templates/Rakefile.tt
@@ -1,9 +1,13 @@
require 'bundler'
Bundler::GemHelper.install_tasks
-require 'rspec/core/rake_task'
+require 'rake/testtask'
desc "Run <%= underscored %> specs"
-RSpec::Core::RakeTask.new
+Rake::TestTask.new do |t|
+ t.libs << "spec"
+ t.test_files = FileList['spec/**/*_spec.rb']
+ t.verbose = true
+end
require 'yard'
YARD::Rake::YardocTask.new(:docs) do |t|
@@ -44,4 +48,4 @@ task :graph do |t|
`bundle exec yard graph -d --full --no-private | dot -Tpng -o graph.png && open graph.png`
end
-task :default => [:spec]
+task :default => [:test]
View
47 lib/gram/gem/templates/Rakefile_rspec.tt
@@ -0,0 +1,47 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+desc "Run <%= underscored %> specs"
+RSpec::Core::RakeTask.new
+
+require 'yard'
+YARD::Rake::YardocTask.new(:docs) do |t|
+ t.files = ['lib/**/*.rb']
+ t.options = ['-m', 'markdown', '--no-private', '-r', 'Readme.md', '--title', '<%= camelized %> documentation']
+end
+
+site = 'doc'
+source_branch = 'master'
+deploy_branch = 'gh-pages'
+
+desc "generate and deploy documentation website to github pages"
+multitask :pages do
+ puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
+ require 'git'
+ repo = Git.open('.')
+ puts "\n>>> Checking out #{deploy_branch} branch <<<\n"
+ repo.branch("#{deploy_branch}").checkout
+ (Dir["*"] - [site]).each { |f| rm_rf(f) }
+ Dir["#{site}/*"].each {|f| mv(f, "./")}
+ rm_rf(site)
+ puts "\n>>> Moving generated site files <<<\n"
+ Dir["**/*"].each {|f| repo.add(f) }
+ repo.status.deleted.each {|f, s| repo.remove(f)}
+ puts "\n>>> Commiting: Site updated at #{Time.now.utc} <<<\n"
+ message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
+ repo.commit(message)
+ puts "\n>>> Pushing generated site to #{deploy_branch} branch <<<\n"
+ repo.push
+ puts "\n>>> Github Pages deploy complete <<<\n"
+ repo.branch("#{source_branch}").checkout
+end
+
+task :doc => [:docs]
+
+desc "Generate and open class diagram (needs Graphviz installed)"
+task :graph do |t|
+ `bundle exec yard graph -d --full --no-private | dot -Tpng -o graph.png && open graph.png`
+end
+
+task :default => [:spec]
View
22 lib/gram/gem/templates/spec/minispec_helper.tt
@@ -0,0 +1,22 @@
+gem 'minitest'
+require 'minitest/spec'
+require 'minitest/autorun'
+require 'mocha'
+
+require '<%= underscored %>'
+<% if rails %>
+
+ActiveRecord::Base.establish_connection(
+ :adapter => 'sqlite3',
+ :database => ':memory:'
+)
+
+ActiveRecord::Schema.define do
+ create_table :articles do |t|
+ t.string :name
+ t.integer :price
+
+ t.timestamps
+ end
+end
+<% end %>
View
0 lib/gram/gem/templates/spec/spec_helper.tt → lib/gram/gem/templates/spec/rspec_helper.tt
File renamed without changes.
View
2 lib/gram/version.rb
@@ -1,3 +1,3 @@
module Gram
- VERSION = '0.1.0'
+ VERSION = '0.2.0'
end
View
96 spec/gram/gem/generator_spec.rb
@@ -38,7 +38,8 @@ module Gem
file ".rvmrc"
file "Readme.md"
file "my_gem.gemspec" do
- contains "rspec"
+ contains "minitest"
+ contains "mocha"
contains "yard"
contains "bluecloth"
end
@@ -49,45 +50,80 @@ module Gem
end
end
directory "spec" do
- file "spec_helper.rb"
+ file "spec_helper.rb" do
+ contains "minitest/spec"
+ end
end
end
}
end
+ end
- context 'with --rails' do
- it 'creates a new rails-ready gem' do
- FileUtils.chdir File.expand_path('../../../../tmp', __FILE__)
- Generator.new.generate('my_gem', ['--rails'])
- destination_root.should have_structure {
- directory "my_gem" do
- file "Gemfile"
- file "Rakefile"
- file ".gitignore"
- file ".rvmrc"
- file "Readme.md"
- file "my_gem.gemspec" do
- contains "activerecord"
- contains "sqlite3"
+ context 'with --rails' do
+ it 'creates a new rails-ready gem' do
+ FileUtils.chdir File.expand_path('../../../../tmp', __FILE__)
+ Generator.new.generate('my_gem', ['--rails'])
+ destination_root.should have_structure {
+ directory "my_gem" do
+ file "Gemfile"
+ file "Rakefile"
+ file ".gitignore"
+ file ".rvmrc"
+ file "Readme.md"
+ file "my_gem.gemspec" do
+ contains "activerecord"
+ contains "sqlite3"
- contains "rspec"
- contains "yard"
- contains "bluecloth"
+ contains "minitest"
+ contains "mocha"
+ contains "bluecloth"
+ end
+ directory "lib" do
+ file "my_gem.rb"
+ directory "my_gem" do
+ file "version.rb"
end
- directory "lib" do
- file "my_gem.rb"
- directory "my_gem" do
- file "version.rb"
- end
+ end
+ directory "spec" do
+ file "spec_helper.rb" do
+ contains "minitest/spec"
+ contains "ActiveRecord"
+ end
+ end
+ end
+ }
+ end
+ end
+
+ context 'with --rspec' do
+ it 'creates a new rspec-ready gem' do
+ FileUtils.chdir File.expand_path('../../../../tmp', __FILE__)
+ Generator.new.generate('my_gem', ['--rspec'])
+ destination_root.should have_structure {
+ directory "my_gem" do
+ file "Gemfile"
+ file "Rakefile"
+ file ".gitignore"
+ file ".rvmrc"
+ file "Readme.md"
+ file "my_gem.gemspec" do
+ contains "rspec"
+ contains "yard"
+ contains "bluecloth"
+ end
+ directory "lib" do
+ file "my_gem.rb"
+ directory "my_gem" do
+ file "version.rb"
end
- directory "spec" do
- file "spec_helper.rb" do
- contains "ActiveRecord"
- end
+ end
+ directory "spec" do
+ file "spec_helper.rb" do
+ contains "rspec"
end
end
- }
- end
+ end
+ }
end
end

0 comments on commit c1c50c4

Please sign in to comment.