diff --git a/Changelog.md b/Changelog.md index 2c39be1e..269915c6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,6 @@ # v0.2.4 2012-12-08 +* [feature] define block arguments * [feature] Mutate block arguments, inklusive pattern args * [feature] Recurse into block bodies * [fixed] Crash on mutating yield, added a noop for now diff --git a/lib/mutant/mutator/node/define.rb b/lib/mutant/mutator/node/define.rb index 65e2f6c8..f02b3b00 100644 --- a/lib/mutant/mutator/node/define.rb +++ b/lib/mutant/mutator/node/define.rb @@ -4,9 +4,26 @@ module Mutant class Define < self handle(Rubinius::AST::Define) - handle(Rubinius::AST::DefineSingleton) handle(Rubinius::AST::DefineSingletonScope) + private + + # Emit mutations + # + # @return [undefined] + # + # @api private + # + def dispatch + emit_attribute_mutations(:body) + emit_attribute_mutations(:arguments) + end + end + + class DefineSingleton < self + + handle(Rubinius::AST::DefineSingleton) + private # Emit mutations diff --git a/spec/unit/mutant/mutator/node/define/mutation_spec.rb b/spec/unit/mutant/mutator/node/define/mutation_spec.rb index 84b5aa41..a32ba58d 100644 --- a/spec/unit/mutant/mutator/node/define/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/define/mutation_spec.rb @@ -23,6 +23,35 @@ describe Mutant::Mutator, 'define' do it_should_behave_like 'a mutator' end + context 'with arguments' do + let(:source) { 'def foo(a, b); nil; end' } + + before do + Mutant::Random.stub(:hex_string => 'random') + end + + let(:mutations) do + mutations = [] + + # Deletion of each argument + mutations << 'def foo(a); nil; end' + mutations << 'def foo(b); nil; end' + + # Deletion of all arguments + mutations << 'def foo; nil; end' + + # Rename each argument + mutations << 'def foo(srandom, b); nil; end' + mutations << 'def foo(a, srandom); nil; end' + + # Mutation of body + mutations << 'def foo(a, b); Object.new; end' + end + + + it_should_behave_like 'a mutator' + end + context 'define on singleton' do let(:source) { 'def self.foo; self.bar; self.baz; end' } @@ -44,4 +73,32 @@ describe Mutant::Mutator, 'define' do it_should_behave_like 'a mutator' end + context 'define on singleton with argument' do + + before do + Mutant::Random.stub(:hex_string => 'random') + end + + let(:source) { 'def self.foo(a, b); nil; end' } + + let(:mutations) do + mutations = [] + + # Deletion of each argument + mutations << 'def self.foo(a); nil; end' + mutations << 'def self.foo(b); nil; end' + + # Deletion of all arguments + mutations << 'def self.foo; nil; end' + + # Rename each argument + mutations << 'def self.foo(srandom, b); nil; end' + mutations << 'def self.foo(a, srandom); nil; end' + + # Mutation of body + mutations << 'def self.foo(a, b); Object.new; end' + end + + it_should_behave_like 'a mutator' + end end