From 942132bda297eb5c54823fd63f4d5480c3309604 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 12 May 2006 04:41:23 +0000 Subject: rake test:recent understands subdirectories. Closes #2925. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4337 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/lib/tasks/testing.rake | 25 ++++++++++++++++++++----- 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 -- cgit v1.2.3