Make Classifier.build raise exception on invalid matcher notation

This commit is contained in:
Markus Schirp 2013-09-09 00:05:49 +02:00
parent e8a8c832e2
commit 45f074dbee
2 changed files with 15 additions and 6 deletions

View file

@ -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

View file

@ -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