From 0cba6a9be0d14eb227b719c31fc14d8198be6cf5 Mon Sep 17 00:00:00 2001 From: Henrich Moraes Date: Mon, 10 Feb 2020 13:03:37 -0300 Subject: [PATCH] Fix Simplecov integration Why? Since 0.18 version, Simplecov.start cannot be called twice. So we only start Simplecov when it isn't running. --- .../map_generator/coverage_strategy.rb | 2 +- spec/map_generator/coverage_strategy_spec.rb | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/crystalball/map_generator/coverage_strategy.rb b/lib/crystalball/map_generator/coverage_strategy.rb index 669c3134..129e2ce0 100644 --- a/lib/crystalball/map_generator/coverage_strategy.rb +++ b/lib/crystalball/map_generator/coverage_strategy.rb @@ -17,7 +17,7 @@ def initialize(execution_detector = ExecutionDetector.new) end def after_register - Coverage.start + Coverage.start unless Coverage.running? end # Adds to the example_map's used files the ones the ones in which diff --git a/spec/map_generator/coverage_strategy_spec.rb b/spec/map_generator/coverage_strategy_spec.rb index 0789b7a5..91e0ffae 100644 --- a/spec/map_generator/coverage_strategy_spec.rb +++ b/spec/map_generator/coverage_strategy_spec.rb @@ -9,9 +9,20 @@ include_examples 'base strategy' describe '#after_register' do - it 'starts coverage' do - expect(Coverage).to receive(:start) - subject.after_register + context 'when Coverage is already running' do + it 'does nothing' do + allow(Coverage).to receive(:running?).and_return(true) + expect(Coverage).not_to receive(:start) + subject.after_register + end + end + + context 'when Coverage is not running' do + it 'starts coverage' do + allow(Coverage).to receive(:running?).and_return(false) + expect(Coverage).to receive(:start) + subject.after_register + end end end