Skip to content

Commit b4365fb

Browse files
committed
Ensure that coverage dir is removed before running test suite
Signed-off-by: M. Scott Ford <[email protected]>
1 parent eaf308c commit b4365fb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Rakefile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,39 @@ Bundler.setup
99
require 'bundler/gem_tasks'
1010
require "cucumber/rake/task"
1111
require "rspec/core/rake_task"
12+
require 'rake/clean'
13+
14+
# Work around a bug in `rake/clean` from `rake` versions older than 13. It's
15+
# failing when it calls `FileUtils::rm_r` because that method needs to receive
16+
# the `opts` parameter as parameters instead of as a `Hash`.
17+
module Rake
18+
module Cleaner
19+
module_function
20+
21+
def cleanup(file_name, **opts)
22+
begin
23+
opts = { verbose: Rake.application.options.trace }.merge(opts)
24+
rm_r file_name, **opts
25+
rescue StandardError => ex
26+
puts "Failed to remove #{file_name}: #{ex}" unless file_already_gone?(file_name)
27+
end
28+
end
29+
end
30+
end
31+
32+
# Remove the `coverage` directory when the `:clobber` task is run.
33+
CLOBBER.include('coverage')
1234

1335
Cucumber::Rake::Task.new do |t|
1436
t.cucumber_opts = %w(--format progress)
1537
end
1638

1739
RSpec::Core::RakeTask.new('spec')
1840

41+
# Run the `clobber` task when running the entire test suite, because the
42+
# coverage information reported by `simplecov` can be skewed when a `coverage`
43+
# directory is already present.
1944
desc "Run the whole test suite."
20-
task test: [:spec, :cucumber]
45+
task test: [:clobber, :spec, :cucumber]
2146

2247
task default: :test

0 commit comments

Comments
 (0)