Add simple mutator for defines
This commit is contained in:
parent
6f8d4e1cfa
commit
7644a06f33
3 changed files with 47 additions and 1 deletions
|
@ -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'
|
||||
|
|
24
lib/mutant/mutator/define.rb
Normal file
24
lib/mutant/mutator/define.rb
Normal 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
|
22
spec/unit/mutant/mutator/define/mutation_spec.rb
Normal file
22
spec/unit/mutant/mutator/define/mutation_spec.rb
Normal 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
|
Loading…
Reference in a new issue