Skip to content

Commit 633b4b9

Browse files
committed
Disable simplecov on travis-ci
MSP-11671 `bundler install --without coverage` will not install `simplecov`. Running without simplecov changes the average runtime of `rake cucumber:boot` from (n=13) 112.50 seconds to (n=10) 32.17 seconds (-71.41%). (-73.68% from 2c1203b.) Raw data: https://docs.google.com/spreadsheets/d/1vCRi_38Go3Wfq670eDCXMTSSXL1blSbk6NQsgpOqfYw/edit?usp=sharing.
1 parent 08a8cee commit 633b4b9

File tree

6 files changed

+43
-27
lines changed

6 files changed

+43
-27
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
bundler_env: --without coverage
12
env:
23
- RAKE_TASK=cucumber
34
- RAKE_TASK=cucumber:boot

Gemfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ source 'https://rubygems.org'
33
# spec.add_runtime_dependency '<name>', [<version requirements>]
44
gemspec name: 'metasploit-framework'
55

6+
# separate from test as simplecov is not run on travis-ci
7+
group :coverage do
8+
# code coverage for tests
9+
# any version newer than 0.5.4 gives an Encoding error when trying to read the source files.
10+
# see: https://github.com/colszowka/simplecov/issues/127 (hopefully fixed in 0.8.0)
11+
gem 'simplecov', '0.5.4', :require => false
12+
end
13+
614
group :db do
715
gemspec name: 'metasploit-framework-db'
816
end
@@ -44,10 +52,6 @@ group :test do
4452
# cucumber + automatic database cleaning with database_cleaner
4553
gem 'cucumber-rails', :require => false
4654
gem 'shoulda-matchers'
47-
# code coverage for tests
48-
# any version newer than 0.5.4 gives an Encoding error when trying to read the source files.
49-
# see: https://github.com/colszowka/simplecov/issues/127 (hopefully fixed in 0.8.0)
50-
gem 'simplecov', '0.5.4', :require => false
5155
# Manipulate Time.now in specs
5256
gem 'timecop'
5357
end

config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
Bundler.require(
1111
*Rails.groups(
12+
coverage: [:test],
1213
db: all_environments,
1314
pcap: all_environments
1415
)

features/support/hooks.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44
@aruba_timeout_seconds = 8.minutes
55
end
66

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
7+
# don't setup child processes to load simplecov_setup.rb if simplecov isn't installed
8+
unless Bundler.settings.without.include?(:coverage)
9+
Before do |scenario|
10+
command_name = case scenario
11+
when Cucumber::Ast::Scenario, Cucumber::Ast::ScenarioOutline
12+
"#{scenario.feature.title} #{scenario.name}"
13+
when Cucumber::Ast::OutlineTable::ExampleRow
14+
scenario_outline = scenario.scenario_outline
1315

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
16+
"#{scenario_outline.feature.title} #{scenario_outline.name} #{scenario.name}"
17+
else
18+
raise TypeError, "Don't know how to extract command name from #{scenario.class}"
19+
end
1820

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)
21+
# Used in simplecov_setup so that each scenario has a different name and their coverage results are merged instead
22+
# of overwriting each other as 'Cucumber Features'
23+
set_env('SIMPLECOV_COMMAND_NAME', command_name)
2224

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', "#{ENV['RUBYOPT']} -r#{simplecov_setup_pathname}")
25+
simplecov_setup_pathname = Pathname.new(__FILE__).expand_path.parent.join('simplecov_setup')
26+
# set environment variable so child processes will merge their coverage data with parent process's coverage data.
27+
set_env('RUBYOPT', "#{ENV['RUBYOPT']} -r#{simplecov_setup_pathname}")
28+
end
2629
end

features/support/simplecov_setup.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# @note this file is loaded in env.rb to setup simplecov using RUBYOPTs for child processes
22

3-
require 'simplecov'
3+
simplecov_command_name = ENV['SIMPLECOV_COMMAND_NAME']
44

5-
require 'pathname'
5+
# will not be set if hook does not run because `bundle install --without coverage`
6+
if simplecov_command_name
7+
require 'simplecov'
68

7-
root = Pathname(__FILE__).expand_path.parent.parent.parent
9+
require 'pathname'
810

9-
SimpleCov.command_name(ENV['SIMPLECOV_COMMAND_NAME'])
10-
SimpleCov.root(root)
11-
load root.join('.simplecov')
11+
root = Pathname(__FILE__).expand_path.parent.parent.parent
12+
13+
SimpleCov.command_name(simplecov_command_name)
14+
SimpleCov.root(root)
15+
load root.join('.simplecov')
16+
end

spec/spec_helper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# -*- coding: binary -*-
22
ENV['RAILS_ENV'] = 'test'
33

4-
require 'simplecov'
4+
unless Bundler.settings.without.include?(:coverage)
5+
require 'simplecov'
6+
end
57

68
# @note must be before loading config/environment because railtie needs to be loaded before
79
# `Metasploit::Framework::Application.initialize!` is called.

0 commit comments

Comments
 (0)