Cut down even further on rake -T noise

This commit is contained in:
David Heinemeier Hansson 2010-06-09 17:14:47 -04:00
parent 211799450d
commit 983815632c
4 changed files with 91 additions and 36 deletions

View File

@ -5,7 +5,7 @@ namespace :db do
end end
namespace :create do namespace :create do
desc 'Create all the local databases defined in config/database.yml' # desc 'Create all the local databases defined in config/database.yml'
task :all => :load_config do task :all => :load_config do
ActiveRecord::Base.configurations.each_value do |config| ActiveRecord::Base.configurations.each_value do |config|
# Skip entries that don't have a database key, such as the first entry here: # Skip entries that don't have a database key, such as the first entry here:
@ -26,7 +26,7 @@ namespace :db do
end end
end end
desc 'Create the database defined in config/database.yml for the current Rails.env - also makes test database if in development mode' desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
task :create => :load_config do task :create => :load_config do
# Make the test database at the same time as the development one, if it exists # Make the test database at the same time as the development one, if it exists
if Rails.env.development? && ActiveRecord::Base.configurations['test'] if Rails.env.development? && ActiveRecord::Base.configurations['test']
@ -100,7 +100,7 @@ namespace :db do
end end
namespace :drop do namespace :drop do
desc 'Drops all the local databases defined in config/database.yml' # desc 'Drops all the local databases defined in config/database.yml'
task :all => :load_config do task :all => :load_config do
ActiveRecord::Base.configurations.each_value do |config| ActiveRecord::Base.configurations.each_value do |config|
# Skip entries that don't have a database key # Skip entries that don't have a database key
@ -115,7 +115,7 @@ namespace :db do
end end
end end
desc 'Drops the database for the current Rails.env' desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
task :drop => :load_config do task :drop => :load_config do
config = ActiveRecord::Base.configurations[Rails.env || 'development'] config = ActiveRecord::Base.configurations[Rails.env || 'development']
begin begin
@ -142,7 +142,7 @@ namespace :db do
end end
namespace :migrate do namespace :migrate do
desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).' # desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
task :redo => :environment do task :redo => :environment do
if ENV["VERSION"] if ENV["VERSION"]
Rake::Task["db:migrate:down"].invoke Rake::Task["db:migrate:down"].invoke
@ -153,10 +153,10 @@ namespace :db do
end end
end end
desc 'Resets your database using your migrations for the current environment' # desc 'Resets your database using your migrations for the current environment'
task :reset => ["db:drop", "db:create", "db:migrate"] task :reset => ["db:drop", "db:create", "db:migrate"]
desc 'Runs the "up" for a given migration VERSION.' # desc 'Runs the "up" for a given migration VERSION.'
task :up => :environment do task :up => :environment do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version raise "VERSION is required" unless version
@ -164,7 +164,7 @@ namespace :db do
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end end
desc 'Runs the "down" for a given migration VERSION.' # desc 'Runs the "down" for a given migration VERSION.'
task :down => :environment do task :down => :environment do
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
raise "VERSION is required" unless version raise "VERSION is required" unless version
@ -187,7 +187,7 @@ namespace :db do
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end end
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.' # desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
task :reset => [ 'db:drop', 'db:setup' ] task :reset => [ 'db:drop', 'db:setup' ]
# desc "Retrieves the charset for the current environment's database" # desc "Retrieves the charset for the current environment's database"
@ -240,7 +240,7 @@ namespace :db do
end end
end end
desc 'Create the database, load the schema, and initialize with the seed data' desc 'Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)'
task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ] task :setup => [ 'db:create', 'db:schema:load', 'db:seed' ]
desc 'Load the seed data from db/seeds.rb' desc 'Load the seed data from db/seeds.rb'
@ -263,7 +263,7 @@ namespace :db do
end end
end end
desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures." # desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :identify => :environment do task :identify => :environment do
require 'active_record/fixtures' require 'active_record/fixtures'
@ -347,7 +347,7 @@ namespace :db do
end end
namespace :test do namespace :test do
desc "Recreate the test database from the current schema.rb" # desc "Recreate the test database from the current schema.rb"
task :load => 'db:test:purge' do task :load => 'db:test:purge' do
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test']) ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
ActiveRecord::Schema.verbose = false ActiveRecord::Schema.verbose = false
@ -391,7 +391,7 @@ namespace :db do
end end
end end
desc "Empty the test database" # desc "Empty the test database"
task :purge => :environment do task :purge => :environment do
abcs = ActiveRecord::Base.configurations abcs = ActiveRecord::Base.configurations
case abcs["test"]["adapter"] case abcs["test"]["adapter"]

View File

@ -1,13 +1,43 @@
require 'rake/rdoctask' require 'rake/rdoctask'
# Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise
class RDocTaskWithoutDescriptions < Rake::RDocTask
def define
task rdoc_task_name
task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
task clobber_task_name do
rm_r rdoc_dir rescue nil
end
task :clobber => [clobber_task_name]
directory @rdoc_dir
task rdoc_task_name => [rdoc_target]
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
rm_r @rdoc_dir rescue nil
@before_running_rdoc.call if @before_running_rdoc
args = option_list + @rdoc_files
if @external
argstring = args.join(' ')
sh %{ruby -Ivendor vendor/rd #{argstring}}
else
require 'rdoc/rdoc'
RDoc::RDoc.new.document(args)
end
end
self
end
end
namespace :doc do namespace :doc do
def gem_path(gem_name) def gem_path(gem_name)
path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first path = $LOAD_PATH.grep(/#{gem_name}[\w.-]*\/lib$/).first
yield File.dirname(path) if path yield File.dirname(path) if path
end end
desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\"" RDocTaskWithoutDescriptions.new("app") { |rdoc|
Rake::RDocTask.new("app") { |rdoc|
rdoc.rdoc_dir = 'doc/app' rdoc.rdoc_dir = 'doc/app'
rdoc.template = ENV['template'] if ENV['template'] rdoc.template = ENV['template'] if ENV['template']
rdoc.title = ENV['title'] || "Rails Application Documentation" rdoc.title = ENV['title'] || "Rails Application Documentation"
@ -17,9 +47,10 @@ namespace :doc do
rdoc.rdoc_files.include('app/**/*.rb') rdoc.rdoc_files.include('app/**/*.rb')
rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb')
} }
Rake::Task['doc:app'].comment = "Generate docs for the app -- also availble doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")"
desc 'Generate documentation for the Rails framework.' # desc 'Generate documentation for the Rails framework.'
Rake::RDocTask.new("rails") { |rdoc| RDocTaskWithoutDescriptions.new("rails") { |rdoc|
rdoc.rdoc_dir = 'doc/api' rdoc.rdoc_dir = 'doc/api'
rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.template = "#{ENV['template']}.rb" if ENV['template']
rdoc.title = "Rails Framework Documentation" rdoc.title = "Rails Framework Documentation"
@ -71,15 +102,15 @@ namespace :doc do
plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) } plugins = FileList['vendor/plugins/**'].collect { |plugin| File.basename(plugin) }
desc "Generate documentation for all installed plugins" # desc "Generate documentation for all installed plugins"
task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" } task :plugins => plugins.collect { |plugin| "doc:plugins:#{plugin}" }
desc "Remove plugin documentation" # desc "Remove plugin documentation"
task :clobber_plugins do task :clobber_plugins do
rm_rf 'doc/plugins' rescue nil rm_rf 'doc/plugins' rescue nil
end end
desc "Generate Rails Guides" # desc "Generate Rails Guides"
task :guides do task :guides do
# FIXME: Reaching outside lib directory is a bad idea # FIXME: Reaching outside lib directory is a bad idea
require File.expand_path('../../../../guides/rails_guides', __FILE__) require File.expand_path('../../../../guides/rails_guides', __FILE__)
@ -89,7 +120,7 @@ namespace :doc do
namespace :plugins do namespace :plugins do
# Define doc tasks for each plugin # Define doc tasks for each plugin
plugins.each do |plugin| plugins.each do |plugin|
desc "Generate documentation for the #{plugin} plugin" # desc "Generate documentation for the #{plugin} plugin"
task(plugin => :environment) do task(plugin => :environment) do
plugin_base = "vendor/plugins/#{plugin}" plugin_base = "vendor/plugins/#{plugin}"
options = [] options = []

View File

@ -7,13 +7,13 @@ task :rails_env do
end end
end end
desc 'Generate a crytographically secure secret key (rhis is typically used to generate a secret for cookie sessions).' desc 'Generate a crytographically secure secret key (this is typically used to generate a secret for cookie sessions).'
task :secret do task :secret do
require 'active_support/secure_random' require 'active_support/secure_random'
puts ActiveSupport::SecureRandom.hex(64) puts ActiveSupport::SecureRandom.hex(64)
end end
desc 'Explain the current environment' desc 'List versions of all Rails frameworks and the environment'
task :about do task :about do
puts Rails::Info puts Rails::Info
end end

View File

@ -1,5 +1,35 @@
require 'rake/testtask' require 'rake/testtask'
# Monkey-patch to silence the description from Rake::TestTask to cut down on rake -T noise
class TestTaskWithoutDescription < Rake::TestTask
# Create the tasks defined by this task lib.
def define
lib_path = @libs.join(File::PATH_SEPARATOR)
task @name do
run_code = ''
RakeFileUtils.verbose(@verbose) do
run_code =
case @loader
when :direct
"-e 'ARGV.each{|f| load f}'"
when :testrb
"-S testrb #{fix}"
when :rake
rake_loader
end
@ruby_opts.unshift( "-I\"#{lib_path}\"" )
@ruby_opts.unshift( "-w" ) if @warning
ruby @ruby_opts.join(" ") +
" \"#{run_code}\" " +
file_list.collect { |fn| "\"#{fn}\"" }.join(' ') +
" #{option_list}"
end
end
self
end
end
TEST_CHANGES_SINCE = Time.now - 600 TEST_CHANGES_SINCE = Time.now - 600
# Look up tests for recently modified sources. # Look up tests for recently modified sources.
@ -40,7 +70,7 @@ module Kernel
end end
end end
desc 'Run all unit, functional and integration tests' desc 'Runs test:unit, test:functional, test:integration together (also available: test:benchmark, test:profile, test:plugins)'
task :test do task :test do
errors = %w(test:units test:functionals test:integration).collect do |task| errors = %w(test:units test:functionals test:integration).collect do |task|
begin begin
@ -92,38 +122,33 @@ namespace :test do
end end
Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)"
Rake::TestTask.new(:units => "test:prepare") do |t| TestTaskWithoutDescription.new(:units => "test:prepare") do |t|
t.libs << "test" t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb' t.pattern = 'test/unit/**/*_test.rb'
end end
Rake::Task['test:units'].comment = "Run the unit tests in test/unit"
Rake::TestTask.new(:functionals => "test:prepare") do |t| TestTaskWithoutDescription.new(:functionals => "test:prepare") do |t|
t.libs << "test" t.libs << "test"
t.pattern = 'test/functional/**/*_test.rb' t.pattern = 'test/functional/**/*_test.rb'
end end
Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional"
Rake::TestTask.new(:integration => "test:prepare") do |t| TestTaskWithoutDescription.new(:integration => "test:prepare") do |t|
t.libs << "test" t.libs << "test"
t.pattern = 'test/integration/**/*_test.rb' t.pattern = 'test/integration/**/*_test.rb'
end end
Rake::Task['test:integration'].comment = "Run the integration tests in test/integration"
Rake::TestTask.new(:benchmark => 'test:prepare') do |t| TestTaskWithoutDescription.new(:benchmark => 'test:prepare') do |t|
t.libs << 'test' t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb' t.pattern = 'test/performance/**/*_test.rb'
t.options = '-- --benchmark' t.options = '-- --benchmark'
end end
Rake::Task['test:benchmark'].comment = 'Benchmark the performance tests'
Rake::TestTask.new(:profile => 'test:prepare') do |t| TestTaskWithoutDescription.new(:profile => 'test:prepare') do |t|
t.libs << 'test' t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb' t.pattern = 'test/performance/**/*_test.rb'
end end
Rake::Task['test:profile'].comment = 'Profile the performance tests'
Rake::TestTask.new(:plugins => :environment) do |t| TestTaskWithoutDescription.new(:plugins => :environment) do |t|
t.libs << "test" t.libs << "test"
if ENV['PLUGIN'] if ENV['PLUGIN']
@ -132,5 +157,4 @@ namespace :test do
t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb' t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb'
end end
end end
Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)"
end end