Skip to content

Commit 617f1bd

Browse files
committed
Adds simplecov and configures it to collect coverage from cucumber
Signed-off-by: M. Scott Ford <[email protected]>
1 parent 313ef44 commit 617f1bd

File tree

6 files changed

+104
-2
lines changed

6 files changed

+104
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
/Gemfile.lock
33
/tmp/aruba
4+
/coverage

.simplecov

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copied from https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/.simplecov
2+
# Licensed under MIT - https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/LICENSE
3+
4+
SimpleCov.configure do
5+
enable_for_subprocesses true
6+
7+
# Activate branch coverage
8+
enable_coverage :branch
9+
10+
# ignore this file
11+
add_filter ".simplecov"
12+
add_filter "features"
13+
14+
# Rake tasks aren't tested with rspec
15+
add_filter "Rakefile"
16+
add_filter "lib/tasks"
17+
18+
#
19+
# Changed Files in Git Group
20+
# @see http://fredwu.me/post/35625566267/simplecov-test-coverage-for-changed-files-only
21+
untracked = `git ls-files --exclude-standard --others`
22+
unstaged = `git diff --name-only`
23+
staged = `git diff --name-only --cached`
24+
all = untracked + unstaged + staged
25+
changed_filenames = all.split("\n")
26+
27+
add_group "Changed" do |source_file|
28+
changed_filenames.select do |changed_filename|
29+
source_file.filename.end_with?(changed_filename)
30+
end
31+
end
32+
33+
add_group "Libraries", "lib"
34+
35+
# Specs are reported on to ensure that all examples are being run and all
36+
# lets, befores, afters, etc are being used.
37+
add_group "Specs", "spec/"
38+
end

Rakefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
#!/usr/bin/env rake
2+
$LOAD_PATH << File.expand_path(__dir__)
3+
4+
require "aruba/platform"
5+
6+
require "bundler"
7+
Bundler.setup
8+
29
require 'bundler/gem_tasks'
3-
require 'rspec/core/rake_task'
10+
require "cucumber/rake/task"
11+
require "rspec/core/rake_task"
12+
13+
Cucumber::Rake::Task.new do |t|
14+
t.cucumber_opts = %w(--format progress)
15+
end
416

517
RSpec::Core::RakeTask.new('spec')
618

7-
task default: :spec
19+
desc "Run the whole test suite."
20+
task test: [:spec, :cucumber]
21+
22+
task default: :test

cyclonedx-ruby.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
2929
spec.add_development_dependency 'rspec', '~> 3.7'
3030
spec.add_development_dependency 'cucumber', '~> 8.0'
3131
spec.add_development_dependency 'aruba', '~> 2.1'
32+
spec.add_development_dependency 'simplecov', '~> 0.22.0'
3233
end

features/support/env.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
# Based on https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/features/support/env.rb
2+
# Licensed under MIT - https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/LICENSE
3+
4+
$LOAD_PATH.unshift File.expand_path('../../lib', __dir__)
5+
6+
# Has to be the first file required so that all other files show coverage information
7+
require_relative 'simplecov_support' unless RUBY_PLATFORM.include?('java')
8+
9+
require 'fileutils'
10+
require 'pathname'
11+
112
require 'aruba/cucumber'
13+
require 'rspec/expectations'
14+
15+
Around do |test_case, block|
16+
command_name = "#{test_case.location.file}:#{test_case.location.line} # #{test_case.name}"
17+
18+
# Used in simplecov_setup so that each scenario has a different name and
19+
# their coverage results are merged instead of overwriting each other as
20+
# 'Cucumber Features'
21+
set_environment_variable 'SIMPLECOV_COMMAND_NAME', command_name.to_s
22+
23+
simplecov_setup_pathname =
24+
Pathname.new(__FILE__).expand_path.parent.to_s
25+
26+
# set environment variable so child processes will merge their coverage data
27+
# with parent process's coverage data.
28+
prepend_environment_variable 'RUBYOPT', "-I#{simplecov_setup_pathname} -rsimplecov_support "
29+
30+
with_environment do
31+
block.call
32+
end
33+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copied from https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/features/support/simplecov_setup.rb
2+
# Licensed under MIT - https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/LICENSE
3+
4+
# @note this file is loaded in env.rb to setup simplecov using RUBYOPTs for
5+
# child processes and @in-process
6+
unless RUBY_PLATFORM.include?('java')
7+
require 'simplecov'
8+
root = File.expand_path('../..', __dir__)
9+
command_name = ENV['SIMPLECOV_COMMAND_NAME'] || 'Cucumber Features'
10+
SimpleCov.command_name(command_name)
11+
SimpleCov.root(root)
12+
13+
# Run simplecov by default
14+
SimpleCov.start unless ENV.key? 'ARUBA_NO_COVERAGE'
15+
end

0 commit comments

Comments
 (0)