Permalink
Browse files

Added 'recent' as a rake target that'll run tests for files that chan…

…ged in the last 10 minutes #612 [bitsweat]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@656 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2713960 commit 2af41fc0367920f7ac6274e057d67b977800ca00 @dhh dhh committed Feb 17, 2005
Showing with 37 additions and 5 deletions.
  1. +2 −0 railties/CHANGELOG
  2. +35 −5 railties/fresh_rakefile
View
@@ -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]
View
@@ -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"

0 comments on commit 2af41fc

Please sign in to comment.