Fixed incompatibilities with Ruby 1.8.6
[arvados.git] / tasks / spec.rake
1 require 'spec/rake/verify_rcov'
2
3 namespace :spec do
4   Spec::Rake::SpecTask.new(:rcov) do |t|
5     t.spec_files = FileList['spec/**/*_spec.rb']
6     t.spec_opts = ['--require', 'rubygems', '--color', '--format', 'specdoc']
7     if RCOV_ENABLED
8       if `which rcov`.strip == ""
9         STDERR.puts "Please install rcov:"
10         STDERR.puts(
11           "sudo gem install relevance-rcov --source http://gems.github.com/"
12         )
13         exit(1)
14       end
15       t.rcov = true
16     else
17       t.rcov = false
18     end
19     t.rcov_opts = [
20       '--exclude', 'spec',
21       '--exclude', '1\\.8\\/gems',
22       '--exclude', '1\\.9\\/gems'
23     ]
24   end
25
26   Spec::Rake::SpecTask.new(:all) do |t|
27     t.spec_files = FileList['spec/**/*_spec.rb']
28     t.spec_opts = ['--require', 'rubygems', '--color', '--format', 'specdoc']
29     t.rcov = false
30   end
31
32   Spec::Rake::SpecTask.new(:fast) do |t|
33     t.spec_files = FileList['spec/**/*_spec.rb'].exclude(
34       'spec/**/*_slow_spec.rb'
35     )
36     t.spec_opts = ['--require', 'rubygems', '--color', '--format', 'specdoc']
37     t.rcov = false
38   end
39
40   if RCOV_ENABLED
41     RCov::VerifyTask.new(:verify) do |t|
42       t.threshold = 100.0
43       t.index_html = 'coverage/index.html'
44     end
45
46     task :verify => :rcov
47   end
48
49   desc 'Generate HTML Specdocs for all specs'
50   Spec::Rake::SpecTask.new(:specdoc) do |t|
51     specdoc_path = File.expand_path(
52       File.join(File.dirname(__FILE__), '../specdoc/'))
53     Dir.mkdir(specdoc_path) if !File.exist?(specdoc_path)
54
55     output_file = File.join(specdoc_path, 'index.html')
56     t.spec_files = FileList['spec/**/*_spec.rb']
57     t.spec_opts = ['--format', "\"html:#{output_file}\"", '--diff']
58     t.fail_on_error = false
59   end
60
61   namespace :rcov do
62     desc 'Browse the code coverage report.'
63     task :browse => 'spec:rcov' do
64       require 'launchy'
65       Launchy::Browser.run('coverage/index.html')
66     end
67   end
68 end
69
70 if RCOV_ENABLED
71   desc 'Alias to spec:verify'
72   task 'spec' => 'spec:verify'
73 else
74   desc 'Alias to spec:all'
75   task 'spec' => 'spec:all'
76 end
77
78 task 'clobber' => ['spec:clobber_rcov']