diff --git a/lib/mutant.rb b/lib/mutant.rb index fef56af5..efb7ce04 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -87,6 +87,7 @@ require 'mutant/mutator/node/if' require 'mutant/mutator/node/case' require 'mutant/mutator/node/splat' require 'mutant/mutator/node/resbody' +require 'mutant/mutator/node/rescue' require 'mutant/config' require 'mutant/loader' require 'mutant/context' diff --git a/lib/mutant/mutator/node/generic.rb b/lib/mutant/mutator/node/generic.rb index 0cb1fc85..e31990ff 100644 --- a/lib/mutant/mutator/node/generic.rb +++ b/lib/mutant/mutator/node/generic.rb @@ -10,9 +10,7 @@ module Mutant # These nodes still need a dedicated mutator, # your contribution is that close! handle( - :ensure, - :rescue, :redo, :defined?, - :regopt, :retry, :arg_expr, + :ensure, :redo, :defined?, :regopt, :retry, :arg_expr, :kwrestarg, :kwoptarg, :kwarg, :undef, :module, :empty, :alias, :for, :xstr, :back_ref, :class, :sclass, :match_with_lvasgn, :match_current_line, :while_post, diff --git a/lib/mutant/mutator/node/rescue.rb b/lib/mutant/mutator/node/rescue.rb new file mode 100644 index 00000000..d4e3e127 --- /dev/null +++ b/lib/mutant/mutator/node/rescue.rb @@ -0,0 +1,26 @@ +# encoding: utf-8 + +module Mutant + class Mutator + class Node + # Mutator for rescue nodes + class Rescue < Generic + + handle :rescue + + # Return identity + # + # @param [Parser::AST::Node] node + # + # @return [String] + # + # @api private + # + def self.identity(node) + super(NodeHelpers.s(:kwbegin, node)) + end + + end # Rescue + end # Node + end # Mutator +end # Mutant diff --git a/spec/unit/mutant/mutator/node/define_spec.rb b/spec/unit/mutant/mutator/node/define_spec.rb index 37806d34..4fcf53e7 100644 --- a/spec/unit/mutant/mutator/node/define_spec.rb +++ b/spec/unit/mutant/mutator/node/define_spec.rb @@ -14,6 +14,19 @@ describe Mutant::Mutator, 'def' do it_should_behave_like 'a mutator' end + context 'empty rescue body' do + let(:source) { "def foo\nfoo\nrescue\nend" } + + let(:mutations) do + mutations = [] + mutations << 'def foo; raise; end' + mutations << 'def foo; nil; rescue; end' + mutations << 'def foo; end' + end + + it_should_behave_like 'a mutator' + end + context 'with no arguments' do let(:source) { 'def foo; true; false; end' }