From 19896c4d29f2772faa45a93fcf18a9c740e77a4a Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sat, 28 Jun 2014 22:54:28 +0000 Subject: [PATCH] Move test selection out of stategy --- lib/mutant/config.rb | 21 +++++++++++++++++++++ lib/mutant/runner/subject.rb | 2 +- lib/mutant/strategy.rb | 21 --------------------- spec/unit/mutant/runner/subject_spec.rb | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/mutant/config.rb b/lib/mutant/config.rb index ef039d97..537a39e9 100644 --- a/lib/mutant/config.rb +++ b/lib/mutant/config.rb @@ -29,5 +29,26 @@ module Mutant self end + # Return tests for mutation + # + # TODO: This logic is now centralized but still fucked. + # + # @param [Mutation] mutation + # + # @return [Enumerable] + # + # @api private + # + def tests(subject) + subject.match_expressions.each do |match_expression| + tests = strategy.all_tests.select do |test| + match_expression.prefix?(test.expression) + end + return tests if tests.any? + end + + EMPTY_ARRAY + end + end # Config end # Mutant diff --git a/lib/mutant/runner/subject.rb b/lib/mutant/runner/subject.rb index 8c949b9f..cc49bd6c 100644 --- a/lib/mutant/runner/subject.rb +++ b/lib/mutant/runner/subject.rb @@ -64,7 +64,7 @@ module Mutant # @api private # def tests - config.strategy.tests(subject) + config.tests(subject) end memoize :tests diff --git a/lib/mutant/strategy.rb b/lib/mutant/strategy.rb index b1dc77e3..3c003ce4 100644 --- a/lib/mutant/strategy.rb +++ b/lib/mutant/strategy.rb @@ -62,27 +62,6 @@ module Mutant # abstract_method :all_tests - # Return tests for mutation - # - # TODO: This logic is now centralized but still fucked. - # - # @param [Mutation] mutation - # - # @return [Enumerable] - # - # @api private - # - def tests(subject) - subject.match_expressions.each do |match_expression| - tests = all_tests.select do |test| - match_expression.prefix?(test.expression) - end - return tests if tests.any? - end - - EMPTY_ARRAY - end - # Null strategy that never kills a mutation class Null < self diff --git a/spec/unit/mutant/runner/subject_spec.rb b/spec/unit/mutant/runner/subject_spec.rb index 5d6754a1..7c88e44c 100644 --- a/spec/unit/mutant/runner/subject_spec.rb +++ b/spec/unit/mutant/runner/subject_spec.rb @@ -30,7 +30,7 @@ describe Mutant::Runner::Subject, '#success?' do let(:tests) { [double('test a'), double('test b')] } before do - expect(strategy).to receive(:tests).with(mutation_subject).and_return(tests) + expect(config).to receive(:tests).with(mutation_subject).and_return(tests) 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