Skip to content

Commit 81d160c

Browse files
limhoff-r7trevrosen
authored andcommitted
Add simplecov to cucumber env
MSP-11647 Port simplecov setup from metasploit-version so that child processes, in this case msfconsole, will load simplecov and report coverage back to the parent process. Coverage from msfconsole's cucumber features is the only way to get coverage on portions of the command dispatcher commands.
1 parent 60a1ec2 commit 81d160c

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

features/support/env.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Has to be the first file required so that all other files show coverage information
2+
require 'simplecov'
3+
14
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
25
# It is recommended to regenerate this file in the future when you upgrade to a
36
# newer version of cucumber-rails. Consider adding your own code to a new file

features/support/hooks.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,25 @@
22
set_env('MSF_DATBASE_CONFIG', Rails.configuration.paths['config/database'].existent.first)
33
set_env('RAILS_ENV', 'test')
44
@aruba_timeout_seconds = 4.minutes
5-
end
5+
end
6+
7+
Before do |scenario|
8+
command_name = case scenario
9+
when Cucumber::Ast::Scenario, Cucumber::Ast::ScenarioOutline
10+
"#{scenario.feature.title} #{scenario.name}"
11+
when Cucumber::Ast::OutlineTable::ExampleRow
12+
scenario_outline = scenario.scenario_outline
13+
14+
"#{scenario_outline.feature.title} #{scenario_outline.name} #{scenario.name}"
15+
else
16+
raise TypeError, "Don't know how to extract command name from #{scenario.class}"
17+
end
18+
19+
# Used in simplecov_setup so that each scenario has a different name and their coverage results are merged instead
20+
# of overwriting each other as 'Cucumber Features'
21+
set_env('SIMPLECOV_COMMAND_NAME', command_name)
22+
23+
simplecov_setup_pathname = Pathname.new(__FILE__).expand_path.parent.join('simplecov_setup')
24+
# set environment variable so child processes will merge their coverage data with parent process's coverage data.
25+
set_env('RUBYOPT', "-r#{simplecov_setup_pathname} #{ENV['RUBYOPT']}")
26+
end

features/support/simplecov_setup.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @note this file is loaded in env.rb to setup simplecov using RUBYOPTs for child processes
2+
3+
require 'simplecov'
4+
5+
require 'pathname'
6+
7+
root = Pathname(__FILE__).expand_path.parent.parent.parent
8+
9+
SimpleCov.command_name(ENV['SIMPLECOV_COMMAND_NAME'])
10+
SimpleCov.root(root)
11+
load root.join('.simplecov')

0 commit comments

Comments
 (0)