diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-17 20:12:27 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-17 20:12:27 +0000 |
commit | 2af41fc0367920f7ac6274e057d67b977800ca00 (patch) | |
tree | 07925890ad1912ae41f2c9cd9c252e19efe8ca06 /railties/fresh_rakefile | |
parent | 2713960dfc2739bcbda7dfeb400bb51913d365a1 (diff) | |
download | rails-2af41fc0367920f7ac6274e057d67b977800ca00.tar.gz rails-2af41fc0367920f7ac6274e057d67b977800ca00.tar.bz2 rails-2af41fc0367920f7ac6274e057d67b977800ca00.zip |
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
Diffstat (limited to 'railties/fresh_rakefile')
-rwxr-xr-x | railties/fresh_rakefile | 40 |
1 files changed, 35 insertions, 5 deletions
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" |