From 2af41fc0367920f7ac6274e057d67b977800ca00 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 17 Feb 2005 20:12:27 +0000 Subject: Added 'recent' as a rake target that'll run tests for files that changed in the last 10 minutes #612 [bitsweat] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@656 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/fresh_rakefile | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 7ba9dc09e9..8bea71c1a2 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added 'recent' as a rake target that'll run tests for files that changed in the last 10 minutes #612 [bitsweat] + * Changed script/console to default to development environment and drop --no-inspect #650 [bitsweat] * Added that the 'fixture :posts' syntax can be used for has_and_belongs_to_many fixtures where a model doesn't exist #572 [bitsweat] diff --git a/railties/fresh_rakefile b/railties/fresh_rakefile index 00086edb0f..c412d99c12 100755 --- a/railties/fresh_rakefile +++ b/railties/fresh_rakefile @@ -3,17 +3,46 @@ require 'rake/testtask' require 'rake/rdoctask' $VERBOSE = nil - -require File.dirname(__FILE__) + '/config/environment' -require 'code_statistics' +TEST_CHANGES_SINCE = Time.now - 600 desc "Run all the tests on a fresh test database" task :default => [ :test_units, :test_functional ] + +desc 'Require application environment.' +task :environment do + unless defined? RAILS_ROOT + require File.dirname(__FILE__) + '/config/environment' + end +end + desc "Generate API documentatio, show coding stats" task :doc => [ :appdoc, :stats ] +# Look up tests for recently modified sources. +def recent_tests(source_pattern, test_path, touched_since = 10.minutes.ago) + FileList[source_pattern].map do |path| + if File.mtime(path) > touched_since + test = "#{test_path}/#{File.basename(path, '.rb')}_test.rb" + test if File.exists?(test) + end + end.compact +end + +desc 'Test recent changes.' +Rake::TestTask.new('recent') do |t| + since = TEST_CHANGES_SINCE + touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + + recent_tests('app/models/*.rb', 'test/unit', since) + + recent_tests('app/controllers/*.rb', 'test/functional', since) + + t.libs << 'test' + t.verbose = true + t.test_files = touched.uniq +end +task :test_recent => [ :clone_structure_to_test ] + desc "Run the unit tests in test/unit" Rake::TestTask.new("test_units") { |t| t.libs << "test" @@ -64,6 +93,7 @@ Rake::RDocTask.new("apidoc") { |rdoc| desc "Report code statistics (KLOCs, etc) from the application" task :stats do + require 'code_statistics' CodeStatistics.new( ["Helpers", "app/helpers"], ["Controllers", "app/controllers"], @@ -93,7 +123,7 @@ task :clone_structure_to_test => [ :db_structure_dump, :purge_test_database ] do end desc "Dump the database structure to a SQL file" -task :db_structure_dump do +task :db_structure_dump => :environment do abcs = ActiveRecord::Base.configurations case abcs[RAILS_ENV]["adapter"] when "mysql" @@ -109,7 +139,7 @@ task :db_structure_dump do end desc "Empty the test database" -task :purge_test_database do +task :purge_test_database => :environment do abcs = ActiveRecord::Base.configurations case abcs["test"]["adapter"] when "mysql" -- cgit v1.2.3