aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-05-12 04:41:23 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-05-12 04:41:23 +0000
commit942132bda297eb5c54823fd63f4d5480c3309604 (patch)
tree8ca1f47169e44c0eedb91abf43951378295afe92
parenta61c1825ab84bcef34e9bba0f21b2b4c650373bb (diff)
downloadrails-942132bda297eb5c54823fd63f4d5480c3309604.tar.gz
rails-942132bda297eb5c54823fd63f4d5480c3309604.tar.bz2
rails-942132bda297eb5c54823fd63f4d5480c3309604.zip
rake test:recent understands subdirectories. Closes #2925.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4337 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/tasks/testing.rake25
2 files changed, 22 insertions, 5 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 0022be6b60..2a0aee1819 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* rake test:recent understands subdirectories. #2925 [jerrett@bravenet.com]
+
* The app generator detects the XAMPP package's MySQL socket location. #3832 [elliot@townx.org]
* The app generator sets a session key in application.rb so apps running on the same host may distinguish their cookies. #2967 [rcoder, rails-bug@owl.me.uk]
diff --git a/railties/lib/tasks/testing.rake b/railties/lib/tasks/testing.rake
index c735c8dbb9..acf70d0c4a 100644
--- a/railties/lib/tasks/testing.rake
+++ b/railties/lib/tasks/testing.rake
@@ -4,10 +4,25 @@ TEST_CHANGES_SINCE = Time.now - 600
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)
+ tests = []
+ source_dir = File.dirname(path).split("/")
+ source_file = File.basename(path, '.rb')
+
+ # Support subdirs in app/models and app/controllers
+ modified_test_path = source_dir.length > 2 ? "#{test_path}/" << source_dir[1..source_dir.length].join('/') : test_path
+
+ # For modified files in app/ run the tests for it. ex. /test/functional/account_controller.rb
+ test = "#{modified_test_path}/#{source_file}_test.rb"
+ tests.push test if File.exists?(test)
+
+ # For modified files in app, run tests in subdirs too. ex. /test/functional/account/*_test.rb
+ test = "#{modified_test_path}/#{File.basename(path, '.rb').sub("_controller","")}"
+ FileList["#{test}/*_test.rb"].each { |f| tests.push f } if File.exists?(test)
+
+ return tests
+
end
- end.compact
+ end.flatten.compact
end
@@ -40,8 +55,8 @@ namespace :test do
Rake::TestTask.new(:recent => "db:test:prepare") 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)
+ recent_tests('app/models/**/*.rb', 'test/unit', since) +
+ recent_tests('app/controllers/**/*.rb', 'test/functional', since)
t.libs << 'test'
t.verbose = true