7e58adfbde7b82079e029da1d3ac08dcafbbb33e
[arvados.git] / tasks / spec.rake
1 require 'rake/clean'
2 require 'rspec/core/rake_task'
3
4 CLOBBER.include('coverage', 'specdoc')
5
6 namespace :spec do
7   RSpec::Core::RakeTask.new(:all) do |t|
8   end
9
10   desc 'Generate HTML Specdocs for all specs.'
11   RSpec::Core::RakeTask.new(:specdoc) do |t|
12     specdoc_path = File.expand_path('../../specdoc', __FILE__)
13
14     t.rspec_opts = %W( --format html --out #{File.join(specdoc_path, 'index.html')} )
15     t.fail_on_error = false
16   end
17
18   RSpec::Core::RakeTask.new(:rcov) do |t|
19     if RCOV_ENABLED
20       if `which rcov`.strip == ""
21         STDERR.puts(
22             "Please install rcov and ensure that its binary is in the PATH:"
23         )
24         STDERR.puts("sudo gem install rcov")
25         exit(1)
26       end
27       t.rcov = true
28     else
29       t.rcov = false
30     end
31     t.rcov_opts = %w(
32          --exclude gems/
33          --exclude spec/
34          --exclude lib/google/api_client/environment.rb
35          --exclude lib/compat
36     )
37   end
38
39   namespace :rcov do
40     desc 'Browse the code coverage report.'
41     task :browse => 'spec:rcov' do
42       require 'launchy'
43       Launchy::Browser.run('coverage/index.html')
44     end
45   end
46 end
47
48 if RCOV_ENABLED
49   desc 'Alias to spec:rcov'
50   task 'spec' => 'spec:rcov'
51 else
52   desc 'Alias to spec:all'
53   task 'spec' => 'spec:all'
54 end