Merge branch 'master' of https://github.com/google/google-api-ruby-client
[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     t.pattern = FileList['spec/**/*_spec.rb']
9     t.rspec_opts = ['--color', '--format', 'documentation']
10     t.rcov = false
11   end
12
13   desc 'Generate HTML Specdocs for all specs.'
14   RSpec::Core::RakeTask.new(:specdoc) do |t|
15     specdoc_path = File.expand_path('../../specdoc', __FILE__)
16
17     t.rspec_opts = %W( --format html --out #{File.join(specdoc_path, 'index.html')} )
18     t.fail_on_error = false
19   end
20
21   RSpec::Core::RakeTask.new(:rcov) do |t|
22     if RCOV_ENABLED
23       if `which rcov`.strip == ""
24         STDERR.puts(
25             "Please install rcov and ensure that its binary is in the PATH:"
26         )
27         STDERR.puts("sudo gem install rcov")
28         exit(1)
29       end
30       t.rcov = true
31     else
32       t.rcov = false
33     end
34     t.rcov_opts = %w(
35          --exclude gems/
36          --exclude spec/
37          --exclude lib/google/api_client/environment.rb
38          --exclude lib/compat
39     )
40   end
41
42   namespace :rcov do
43     desc 'Browse the code coverage report.'
44     task :browse => 'spec:rcov' do
45       require 'launchy'
46       Launchy::Browser.run('coverage/index.html')
47     end
48   end
49 end
50
51 if RCOV_ENABLED
52   desc 'Alias to spec:rcov'
53   task 'spec' => 'spec:rcov'
54 else
55   desc 'Alias to spec:all'
56   task 'spec' => 'spec:all'
57 end