Skip to content

Commit

Permalink
Code coverage: Grab results when using Aruba
Browse files Browse the repository at this point in the history
To run behavior tests, `aruba` executes `bin/msync` directly. In order to allow simplecov to track files, etc. we need to setup it at application start.
  • Loading branch information
neomilium committed Oct 6, 2021
1 parent 85e5a2d commit d33db96
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bin/msync
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
#!/usr/bin/env ruby

if ENV['COVERAGE']
# This block allow us to grab code coverage when running this script.
# Note: This environment variable is set in Cucumber/Aruba configuration to collect reports'
require 'simplecov'

# https://github.com/simplecov-ruby/simplecov/issues/234
# As described in the issue, every process must have an unique name:
SimpleCov.command_name "#{File.basename $PROGRAM_NAME} (pid: #{Process.pid})"

# When running with aruba simplecov was using /tmp/aruba as the root folder.
# This is to force using the project folder
SimpleCov.root(File.join(File.expand_path(File.dirname(__FILE__)), '..'))

SimpleCov.start do
filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults

# Because simplecov filters everything outside of the SimpleCov.root
# This should be added, cf.
# https://github.com/colszowka/simplecov#default-root-filter-and-coverage-for-things-outside-of-it
add_filter do |src|
!(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /project/
end

# Ignoring test folders and tmp for Aruba
add_filter '/spec/'
add_filter '/test/'
add_filter '/features/'
add_filter '/tmp/'
end
end

lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand Down
3 changes: 3 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@

Before do
@aruba_timeout_seconds = 5

# This enables coverage when aruba runs `msync` executable (cf. `bin/msync`)
set_environment_variable('COVERAGE', '1')
end

0 comments on commit d33db96

Please sign in to comment.