diff --git a/lib/mutest.rb b/lib/mutest.rb index 5033f386..377696c7 100644 --- a/lib/mutest.rb +++ b/lib/mutest.rb @@ -179,6 +179,7 @@ def self.ci? require 'mutest/expression/namespace' require 'mutest/test' require 'mutest/integration' +require 'mutest/integration/null' require 'mutest/selector' require 'mutest/selector/expression' require 'mutest/config' @@ -206,6 +207,7 @@ def self.ci? require 'mutest/reporter/cli/tput' require 'mutest/reporter/cli/format' require 'mutest/repository' +require 'mutest/requirer' require 'mutest/zombifier' module Mutest @@ -230,6 +232,7 @@ class Config process: Process ), jobs: ::Parallel.processor_count, + requirer: Requirer.new, kernel: Kernel, load_path: $LOAD_PATH, matcher: Matcher::Config::DEFAULT, diff --git a/lib/mutest/cli.rb b/lib/mutest/cli.rb index 22384c04..c1e73b11 100644 --- a/lib/mutest/cli.rb +++ b/lib/mutest/cli.rb @@ -99,7 +99,7 @@ def add_environment_options(opts) # # @return [undefined] def setup_integration(name) - with(integration: Integration.setup(config.kernel, name)) + with(integration: Integration.setup(config.requirer, name)) rescue LoadError raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutest-#{name})" end diff --git a/lib/mutest/config.rb b/lib/mutest/config.rb index 0970a48d..eeee1b5d 100644 --- a/lib/mutest/config.rb +++ b/lib/mutest/config.rb @@ -16,6 +16,7 @@ class Config :matcher, :open3, :pathname, + :requirer, :requires, :reporter, :zombie diff --git a/lib/mutest/integration.rb b/lib/mutest/integration.rb index ae1954fa..df70c3c6 100644 --- a/lib/mutest/integration.rb +++ b/lib/mutest/integration.rb @@ -47,29 +47,5 @@ def setup def expression_parser config.expression_parser end - - # Null integration that never kills a mutation - class Null < self - # Available tests for integration - # - # @return [Enumerable] - def all_tests - EMPTY_ARRAY - end - - # Run a collection of tests - # - # @param [Enumerable] tests - # - # @return [Result::Test] - def call(tests) - Result::Test.new( - output: '', - passed: true, - runtime: 0.0, - tests: tests - ) - end - end # Null end # Integration end # Mutest diff --git a/lib/mutest/integration/null.rb b/lib/mutest/integration/null.rb new file mode 100644 index 00000000..1de7b154 --- /dev/null +++ b/lib/mutest/integration/null.rb @@ -0,0 +1,27 @@ +module Mutest + class Integration + # Null integration that never kills a mutation + class Null < self + # Available tests for integration + # + # @return [Enumerable] + def all_tests + EMPTY_ARRAY + end + + # Run a collection of tests + # + # @param [Enumerable] tests + # + # @return [Result::Test] + def call(tests) + Result::Test.new( + output: '', + passed: true, + runtime: 0.0, + tests: tests + ) + end + end # Null + end # Integration +end # Mutest diff --git a/lib/mutest/requirer.rb b/lib/mutest/requirer.rb new file mode 100644 index 00000000..da5d530a --- /dev/null +++ b/lib/mutest/requirer.rb @@ -0,0 +1,6 @@ +module Mutest + # Class that exposes #require as a public method + class Requirer + public :require + end # Requirer +end # Mutest diff --git a/spec/unit/mutest/cli_spec.rb b/spec/unit/mutest/cli_spec.rb index d8a320ad..4a5a3895 100644 --- a/spec/unit/mutest/cli_spec.rb +++ b/spec/unit/mutest/cli_spec.rb @@ -137,18 +137,30 @@ end context 'with use flag' do - context 'when integration exists' do + context 'when using the existing integration with rspec' do let(:flags) { %w[--use rspec] } + let(:expected_integration) { Mutest::Integration::Rspec } before do - expect(Kernel).to receive(:require) + expect(Mutest::Config::DEFAULT.requirer).to receive(:require) .with('mutest/integration/rspec') .and_call_original end it_should_behave_like 'a cli parser' + end - let(:expected_integration) { Mutest::Integration::Rspec } + context 'when specifying the default null integration explicitely' do + let(:flags) { %w[--use null] } + let(:expected_integration) { Mutest::Integration::Null } + + before do + expect(Mutest::Config::DEFAULT.requirer).to receive(:require) + .with('mutest/integration/null') + .and_call_original + end + + it_should_behave_like 'a cli parser' end context 'when integration does NOT exist' do diff --git a/spec/unit/mutest/integration_spec.rb b/spec/unit/mutest/integration_spec.rb index 7b028199..cbe5aba4 100644 --- a/spec/unit/mutest/integration_spec.rb +++ b/spec/unit/mutest/integration_spec.rb @@ -11,13 +11,13 @@ end describe '.setup' do - subject { described_class.setup(kernel, name) } + subject { described_class.setup(requirer, name) } - let(:name) { 'null' } - let(:kernel) { class_double(Kernel) } + let(:name) { 'null' } + let(:requirer) { Mutest::Requirer.new } before do - expect(kernel).to receive(:require) + expect(requirer).to receive(:require) .with('mutest/integration/null') end