diff --git a/lib/mutant.rb b/lib/mutant.rb index 095dc319..267dfc1b 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -28,6 +28,16 @@ module Mutant SCOPE_OPERATOR = '::'.freeze + # Test if CI is detected via environment + # + # @return [Boolean] + # + # @api private + # + def self.ci? + ENV.key?('CI') + end + # Lookup constant for location # # @param [String] location @@ -199,6 +209,8 @@ require 'mutant/zombifier/file' module Mutant # Reopen class to initialize constant to avoid dep circle class Config + CI_DEFAULT_PROCESSOR_COUNT = 2 + DEFAULT = new( debug: false, fail_fast: false, @@ -209,7 +221,7 @@ module Mutant isolation: Mutant::Isolation::Fork, reporter: Reporter::CLI.build($stdout), zombie: false, - processes: Parallel.processor_count, + processes: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : Parallel.processor_count, expected_coverage: 100.0 ) end # Config diff --git a/lib/mutant/reporter/cli.rb b/lib/mutant/reporter/cli.rb index 14ec28f7..ac4961be 100644 --- a/lib/mutant/reporter/cli.rb +++ b/lib/mutant/reporter/cli.rb @@ -13,10 +13,9 @@ module Mutant # @api private # def self.build(output) - ci = ENV.key?('CI') tty = output.respond_to?(:tty?) && output.tty? format = - if !ci && tty && Tput::INSTANCE.available + if !Mutant.ci? && tty && Tput::INSTANCE.available Format::Framed.new(tty: tty, tput: Tput::INSTANCE) else Format::Progressive.new(tty: tty) diff --git a/spec/unit/mutant_spec.rb b/spec/unit/mutant_spec.rb index 0abd0ca2..60066fd3 100644 --- a/spec/unit/mutant_spec.rb +++ b/spec/unit/mutant_spec.rb @@ -1,6 +1,18 @@ RSpec.describe Mutant do let(:object) { described_class } + describe '.ci?' do + subject { object.ci? } + + let(:result) { double('Result') } + + before do + expect(ENV).to receive(:key?).with('CI').and_return(result) + end + + it { should be(result) } + end + describe '.zombify' do subject { object.zombify }