Add simple mutator for defines

This commit is contained in:
Markus Schirp 2012-08-14 12:04:48 +02:00
parent 6f8d4e1cfa
commit 7644a06f33
3 changed files with 47 additions and 1 deletions

View file

@ -54,7 +54,7 @@ require 'mutant/mutator/literal/regex'
require 'mutant/mutator/block'
require 'mutant/mutator/noop'
require 'mutant/mutator/call'
require 'mutant/mutator/call'
require 'mutant/mutator/define'
require 'mutant/mutator/if_statement'
require 'mutant/mutator/receiver_case'
require 'mutant/loader'

View file

@ -0,0 +1,24 @@
module Mutant
class Mutator
class Define < self
handle(Rubinius::AST::Define)
private
# Emit mutations
#
# @return [undefined]
#
# @api private
#
def dispatch
Mutator.each(node.body) do |mutation|
node = dup_node
node.body = mutation
emit_safe(node)
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'spec_helper'
describe Mutant::Mutator, 'define' do
context 'with no arguments' do
let(:source) { 'def foo; self.bar; self.baz; end' }
let(:mutations) do
mutations = []
# Mutation of each statement in block
mutations << 'def foo; bar; self.baz; end'
mutations << 'def foo; self.bar; baz; end'
# Remove statement in block
mutations << 'def foo; self.baz; end'
mutations << 'def foo; self.bar; end'
end
it_should_behave_like 'a mutator'
end
end