Files
rails/railties/lib/tasks/testing.rake
David Heinemeier Hansson c45ea78c6a Cleaned it up a bit.. Dependencies can be declared inline
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2570 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-10-13 20:55:05 +00:00

37 lines
1.1 KiB
Ruby

TEST_CHANGES_SINCE = Time.now - 600
# 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 => [ :prepare_test_database ]) 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
desc "Run the unit tests in test/unit"
Rake::TestTask.new(:test_units => [ :prepare_test_database ]) do |t|
t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb'
t.verbose = true
end
desc "Run the functional tests in test/functional"
Rake::TestTask.new(:test_functional => [ :prepare_test_database ]) do |t|
t.libs << "test"
t.pattern = 'test/functional/**/*_test.rb'
t.verbose = true
end