markbates / mack

A Ruby web application framework

This URL has Read+Write access

mack / lib / mack / tasks / test_tasks.rake
100644 63 lines (51 sloc) 1.665 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'rake'
require 'pathname'
require 'spec'
require 'spec/rake/spectask'
 
namespace :test do
  
  task :setup do
  end
  
  desc "Run test code."
  Rake::TestTask.new(:test_case) do |t|
    t.libs << "test"
    t.pattern = 'test/**/*_test.rb'
    t.verbose = true
  end
  
  desc 'Run specifications'
  Spec::Rake::SpecTask.new(:rspec) do |t|
    t.spec_opts << '--options' << 'test/spec.opts' if File.exists?('test/spec.opts')
    t.spec_files = Dir.glob('test/**/*_spec.rb')
  end
  
  desc "Report code statistics (KLOCs, etc) from the application. Requires the rcov gem."
  task :stats do |t|
    ENV["MACK_ENV"] = "test"
    Rake::Task["mack:environment"].invoke
    Rake::Task["test:setup"].invoke
    x = `rcov test/**/*_#{app_config.mack.testing_framework == "rspec" ? "spec" : "test"}.rb -T --no-html -x Rakefile,config\/`
    if app_config.mack.testing_framework == "test_case"
      x.each do |line|
        case line
        when /^\+[\+\-]*\+$/, /^\|.*\|$/, /\d+\sLines\s+\d+\sLOC/
          puts line
        end
      end
    end
  end
  
  desc "Generates test coverage from the application. Requires the rcov gem."
  task :coverage do |t|
    ENV["MACK_ENV"] = "test"
    Rake::Task["mack:environment"].invoke
    Rake::Task["test:setup"].invoke
    `rcov test/**/*_#{app_config.mack.testing_framework == "rspec" ? "spec" : "test"}.rb -x Rakefile,config\/`
    `open coverage/index.html`
  end
  
  task :empty do |t|
    ENV["TEST:EMPTY"] = "true"
  end
  
  task :raise_exception do |t|
    raise "Oh No!"
  end
  
end
 
 
alias_task :default, ["test:setup", "test:rspec"]
alias_task :stats, "test:stats"
alias_task :coverage, "test:coverage"