38578d4b0178daf254ecb08c51edb600264521d3
[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(
10           "Please install rcov and ensure that its binary is in the PATH:"
11         )
12         STDERR.puts("sudo gem install rcov")
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', '\\.rvm\\/gems',
22       '--exclude', '1\\.8\\/gems',
23       '--exclude', '1\\.9\\/gems',
24       '--exclude', '\\.rvm'
25     ]
26   end
27
28   Spec::Rake::SpecTask.new(:all) do |t|
29     t.spec_files = FileList['spec/**/*_spec.rb']
30     t.spec_opts = ['--require', 'rubygems', '--color', '--format', 'specdoc']
31     t.rcov = false
32   end
33
34   Spec::Rake::SpecTask.new(:fast) do |t|
35     t.spec_files = FileList['spec/**/*_spec.rb'].exclude(
36       'spec/**/*_slow_spec.rb'
37     )
38     t.spec_opts = ['--require', 'rubygems', '--color', '--format', 'specdoc']
39     t.rcov = false
40   end
41
42   if RCOV_ENABLED
43     RCov::VerifyTask.new(:verify) do |t|
44       t.threshold = 100.0
45       t.index_html = 'coverage/index.html'
46     end
47
48     task :verify => :rcov
49   end
50
51   desc 'Generate HTML Specdocs for all specs'
52   Spec::Rake::SpecTask.new(:specdoc) do |t|
53     specdoc_path = File.expand_path(
54       File.join(File.dirname(__FILE__), '../specdoc/'))
55     Dir.mkdir(specdoc_path) if !File.exist?(specdoc_path)
56
57     output_file = File.join(specdoc_path, 'index.html')
58     t.spec_files = FileList['spec/**/*_spec.rb']
59     t.spec_opts = ['--format', "\"html:#{output_file}\"", '--diff']
60     t.fail_on_error = false
61   end
62
63   namespace :rcov do
64     desc 'Browse the code coverage report.'
65     task :browse => 'spec:rcov' do
66       require 'launchy'
67       Launchy::Browser.run('coverage/index.html')
68     end
69   end
70 end
71
72 if RCOV_ENABLED
73   desc 'Alias to spec:verify'
74   task 'spec' => 'spec:verify'
75 else
76   desc 'Alias to spec:all'
77   task 'spec' => 'spec:all'
78 end
79
80 task 'clobber' => ['spec:clobber_rcov']