Prefer Kernel#fail over Kernel#raise

This commit is contained in:
Markus Schirp 2014-11-17 17:00:05 +00:00
parent 511702af4c
commit f3720a6366
5 changed files with 10 additions and 10 deletions

View file

@ -44,7 +44,7 @@ module Mutant
# @api private # @api private
# #
def self.find_last_path(node, &predicate) def self.find_last_path(node, &predicate)
raise ArgumentError, 'block expected' unless block_given? fail ArgumentError, 'block expected' unless block_given?
path = [] path = []
walk(node, [node]) do |candidate, stack| walk(node, [node]) do |candidate, stack|
if predicate.call(candidate, &predicate) if predicate.call(candidate, &predicate)

View file

@ -50,7 +50,7 @@ module Mutant
when ::Module when ::Module
s(:module, name, node) s(:module, name, node)
else else
raise "Cannot wrap scope: #{scope.inspect}" fail "Cannot wrap scope: #{scope.inspect}"
end end
end end

View file

@ -25,7 +25,7 @@ module Mutant
methods_matcher = MATCHERS.fetch(scope_symbol).new(env, scope) methods_matcher = MATCHERS.fetch(scope_symbol).new(env, scope)
method = methods_matcher.methods.detect do |meth| method = methods_matcher.methods.detect do |meth|
meth.name.equal?(method_name) meth.name.equal?(method_name)
end or raise NameError, "Cannot find method #{method_name}" end or fail NameError, "Cannot find method #{method_name}"
methods_matcher.matcher.build(env, scope, method) methods_matcher.matcher.build(env, scope, method)
end end

View file

@ -40,7 +40,7 @@ module Mutant
# @api private # @api private
# #
def example def example
raise 'source not defined' unless @source fail 'source not defined' unless @source
Example.new(@file, @source, @expected) Example.new(@file, @source, @expected)
end end
@ -55,7 +55,7 @@ module Mutant
# @api private # @api private
# #
def source(input) def source(input)
raise 'source already defined' if @source fail 'source already defined' if @source
@source = node(input) @source = node(input)
self self
@ -72,7 +72,7 @@ module Mutant
def mutation(input) def mutation(input)
node = node(input) node = node(input)
if @expected.include?(node) if @expected.include?(node)
raise "Node for input: #{input.inspect} is already expected" fail "Node for input: #{input.inspect} is already expected"
end end
@expected << node @expected << node
@ -108,7 +108,7 @@ module Mutant
when Parser::AST::Node when Parser::AST::Node
input input
else else
raise "Cannot coerce to node: #{source.inspect}" fail "Cannot coerce to node: #{source.inspect}"
end end
end end

View file

@ -39,7 +39,7 @@ module Mutant
def self.lookup(node) def self.lookup(node)
type = node.type type = node.type
registry.fetch(type) do registry.fetch(type) do
raise ArgumentError, "No mutator to handle: #{type.inspect}" fail ArgumentError, "No mutator to handle: #{type.inspect}"
end end
end end
@ -67,7 +67,7 @@ module Mutant
# #
def self.assert_valid_type(type) def self.assert_valid_type(type)
unless AST::Types::ALL.include?(type) || type.is_a?(Class) unless AST::Types::ALL.include?(type) || type.is_a?(Class)
raise InvalidTypeError, "invalid type registration: #{type}" fail InvalidTypeError, "invalid type registration: #{type}"
end end
end end
private_class_method :assert_valid_type private_class_method :assert_valid_type
@ -83,7 +83,7 @@ module Mutant
# #
def self.assert_unique_type(type) def self.assert_unique_type(type)
if registry.key?(type) if registry.key?(type)
raise DuplicateTypeError, "duplicate type registration: #{type}" fail DuplicateTypeError, "duplicate type registration: #{type}"
end end
end end
private_class_method :assert_unique_type private_class_method :assert_unique_type