Permalink
Browse files

rake test:recent understands subdirectories. Closes #2925.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4337 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent a61c182 commit 942132bda297eb5c54823fd63f4d5480c3309604 @jeremy jeremy committed May 12, 2006
Showing with 22 additions and 5 deletions.
  1. +2 −0 railties/CHANGELOG
  2. +20 −5 railties/lib/tasks/testing.rake
View
@@ -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]
@@ -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

0 comments on commit 942132b

Please sign in to comment.