From c1b389c28f6d8f825baa956a0b1aca63ba79563c Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Fri, 23 May 2014 01:26:04 +0000 Subject: [PATCH] Use visit_collection in runner to restore --fail-fast behavior --- lib/mutant/runner.rb | 12 +++++----- lib/mutant/runner/mutation.rb | 1 + lib/mutant/runner/subject.rb | 4 +--- spec/unit/mutant/runner/mutation_spec.rb | 28 ++++++++++++++++++++++++ spec/unit/mutant/runner/subject_spec.rb | 4 ++-- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/mutant/runner.rb b/lib/mutant/runner.rb index 1d84456e..9020d061 100644 --- a/lib/mutant/runner.rb +++ b/lib/mutant/runner.rb @@ -48,9 +48,9 @@ module Mutant # # @api private # - def self.run(config, object) + def self.run(config, object, *arguments) handler = lookup(object.class) - handler.new(config, object) + handler.new(config, object, *arguments) end # Return config @@ -153,10 +153,10 @@ module Mutant # # @api private # - def visit_collection(input) + def visit_collection(input, *arguments) collection = [] input.each do |object| - runner = visit(object) + runner = visit(object, *arguments) collection << runner @stop = runner.stop? break if @stop @@ -172,8 +172,8 @@ module Mutant # # @api private # - def visit(object) - Runner.run(config, object) + def visit(object, *arguments) + Runner.run(config, object, *arguments) end end # Runner diff --git a/lib/mutant/runner/mutation.rb b/lib/mutant/runner/mutation.rb index 5710d4d0..415a781a 100644 --- a/lib/mutant/runner/mutation.rb +++ b/lib/mutant/runner/mutation.rb @@ -37,6 +37,7 @@ module Mutant def initialize(config, mutation, tests) @mutation, @tests = mutation, tests super(config) + @stop = config.fail_fast && !success? end # Test if mutation was handeled successfully diff --git a/lib/mutant/runner/subject.rb b/lib/mutant/runner/subject.rb index 399421d3..155e820e 100644 --- a/lib/mutant/runner/subject.rb +++ b/lib/mutant/runner/subject.rb @@ -74,9 +74,7 @@ module Mutant def run progress(subject) tests = config.strategy.tests(subject) - @mutations = subject.mutations.map do |mutation| - Runner::Mutation.new(config, mutation, tests) - end + @mutations = visit_collection(subject.mutations, tests) progress(self) end diff --git a/spec/unit/mutant/runner/mutation_spec.rb b/spec/unit/mutant/runner/mutation_spec.rb index e1d704bd..c946205f 100644 --- a/spec/unit/mutant/runner/mutation_spec.rb +++ b/spec/unit/mutant/runner/mutation_spec.rb @@ -42,6 +42,34 @@ describe Mutant::Runner::Mutation do strategy.stub(killers: killers) end + describe '#stop?' do + subject { object.stop? } + + context 'when fail fast is false' do + it { should be(false) } + end + + context 'when fail fast is true' do + let(:fail_fast) { true } + + context 'when all killers are successful' do + it { should be(false) } + end + + context 'when one killer is NOT successful' do + let(:success_b) { false } + it { should be(false) } + end + + context 'when all killer are NOT successful' do + let(:success_b) { false } + let(:success_a) { false } + + it { should be(true) } + end + end + end + describe '#success?' do subject { object.success? } diff --git a/spec/unit/mutant/runner/subject_spec.rb b/spec/unit/mutant/runner/subject_spec.rb index 056f95c6..96f81b57 100644 --- a/spec/unit/mutant/runner/subject_spec.rb +++ b/spec/unit/mutant/runner/subject_spec.rb @@ -33,8 +33,8 @@ describe Mutant::Runner::Subject, '#success?' do before do expect(strategy).to receive(:tests).with(mutation_subject).and_return(tests) - expect(Mutant::Runner::Mutation).to receive(:new).with(config, mutation_a, tests).and_return(runner_a) - expect(Mutant::Runner::Mutation).to receive(:new).with(config, mutation_b, tests).and_return(runner_b) + expect(Mutant::Runner).to receive(:run).with(config, mutation_a, tests).and_return(runner_a) + expect(Mutant::Runner).to receive(:run).with(config, mutation_b, tests).and_return(runner_b) end context 'with failing mutations' do