testing.rake 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
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

13
desc 'Test recent changes'
14
Rake::TestTask.new(:recent => [ :prepare_test_database ]) do |t|
15 16 17 18 19 20 21 22 23 24 25
  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"
26
Rake::TestTask.new(:test_units => [ :prepare_test_database ]) do |t|
27 28 29
  t.libs << "test"
  t.pattern = 'test/unit/**/*_test.rb'
  t.verbose = true
30
end
31 32

desc "Run the functional tests in test/functional"
33
Rake::TestTask.new(:test_functional => [ :prepare_test_database ]) do |t|
34 35
  t.libs << "test"
  t.pattern = 'test/functional/**/*_test.rb'
36 37 38 39
  t.verbose = true
end

desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)"
40
Rake::TestTask.new(:test_plugins => :environment) do |t|
41 42 43
  t.libs << "test"
  
  if ENV['PLUGIN']
44
    t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb"
45
  else
46
    t.pattern = 'vendor/plugins/**/test/**/*_test.rb'
47 48
  end

49
  t.verbose = true
50
end