From 45f074dbeef2a80b3ef97afdffa044cac18303d5 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 9 Sep 2013 00:05:49 +0200 Subject: [PATCH] Make Classifier.build raise exception on invalid matcher notation --- lib/mutant/cli/classifier.rb | 19 ++++++++++++++----- .../classifier/class_methods/build_spec.rb | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/mutant/cli/classifier.rb b/lib/mutant/cli/classifier.rb index 9ccf6b1a..bc0a4411 100644 --- a/lib/mutant/cli/classifier.rb +++ b/lib/mutant/cli/classifier.rb @@ -54,19 +54,28 @@ module Mutant # Return matchers for input # + # @param [Cache] cache + # @param [String] pattern + # # @return [Classifier] # if a classifier handles the input # - # @return [nil] + # @raise [RuntimeError] # otherwise # # @api private # - def self.build(*arguments) - classifiers = REGISTRY.map { |descendant| descendant.run(*arguments) } + def self.build(cache, pattern) + classifiers = REGISTRY.map { |descendant| descendant.run(cache, pattern) } classifiers.compact! - raise if classifiers.length > 1 - classifiers.first + case classifiers.length + when 0 + raise Error, "No matcher handles: #{pattern.inspect}" + when 1 + return classifiers.first + else + raise Error, "More than one matcher found for: #{pattern.inspect}" + end end # Run classifier diff --git a/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb b/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb index 7229bced..709d8213 100644 --- a/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb +++ b/spec/unit/mutant/cli/classifier/class_methods/build_spec.rb @@ -42,7 +42,7 @@ describe Mutant::CLI::Classifier, '.build' do let(:input) { '::' } it 'should return nil' do - should be(nil) + expect { subject }.to raise_error(Mutant::CLI::Error, "No matcher handles: #{input.inspect}") end end end