diff --git a/lib/mutant/mutator/node/block.rb b/lib/mutant/mutator/node/block.rb index aa5fcee8..0ea07048 100644 --- a/lib/mutant/mutator/node/block.rb +++ b/lib/mutant/mutator/node/block.rb @@ -21,9 +21,8 @@ module Mutant emit_arguments_mutations if body emit_body_mutations - else - emit_body(NEW_OBJECT) end + emit_body(RAISE) end end # Block diff --git a/lib/mutant/mutator/node/define.rb b/lib/mutant/mutator/node/define.rb index 94caf80b..1374bba9 100644 --- a/lib/mutant/mutator/node/define.rb +++ b/lib/mutant/mutator/node/define.rb @@ -14,11 +14,8 @@ module Mutant # def dispatch emit_arguments_mutations - if body - emit_body_mutations - else - emit_body(NEW_OBJECT) - end + emit_body(RAISE) + emit_body_mutations if body end # Mutator for instance method defines diff --git a/lib/mutant/node_helpers.rb b/lib/mutant/node_helpers.rb index 5faf213b..9b07316b 100644 --- a/lib/mutant/node_helpers.rb +++ b/lib/mutant/node_helpers.rb @@ -21,6 +21,8 @@ module Mutant INFINITY = s(:send, s(:float, 1.0), :/, s(:args, s(:float, 0.0))) NEW_OBJECT = s(:send, s(:const, s(:cbase), :Object), :new) + RAISE = s(:send, nil, :raise) + N_NIL = s(:nil) N_EMPTY = s(:empty) diff --git a/spec/unit/mutant/mutator/node/block/mutation_spec.rb b/spec/unit/mutant/mutator/node/block/mutation_spec.rb index 22571fa0..fb7e815b 100644 --- a/spec/unit/mutant/mutator/node/block/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/block/mutation_spec.rb @@ -9,6 +9,7 @@ describe Mutant::Mutator, 'block' do mutations << 'foo { a }' mutations << 'foo { b }' mutations << 'foo {}' + mutations << 'foo { raise }' mutations << 'foo' end @@ -26,7 +27,7 @@ describe Mutant::Mutator, 'block' do let(:mutations) do mutations = [] mutations << 'foo' - mutations << 'foo { |a, b| ::Object.new }' + mutations << 'foo { |a, b| raise }' mutations << 'foo { |a, srandom| }' mutations << 'foo { |srandom, b| }' mutations << 'foo { |a| }' @@ -49,7 +50,7 @@ describe Mutant::Mutator, 'block' do mutations = [] mutations << 'foo { || }' mutations << 'foo { |a, b, c| }' - mutations << 'foo { |(a, b), c| ::Object.new }' + mutations << 'foo { |(a, b), c| raise }' mutations << 'foo { |(a), c| }' mutations << 'foo { |(b), c| }' mutations << 'foo { |(a, b)| }' diff --git a/spec/unit/mutant/mutator/node/define/mutation_spec.rb b/spec/unit/mutant/mutator/node/define/mutation_spec.rb index 14295b31..254ebcb8 100644 --- a/spec/unit/mutant/mutator/node/define/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/define/mutation_spec.rb @@ -7,7 +7,7 @@ describe Mutant::Mutator, 'def' do let(:mutations) do mutations = [] - mutations << 'def foo; ::Object.new; end' + mutations << 'def foo; raise; end' end it_should_behave_like 'a mutator' @@ -31,6 +31,8 @@ describe Mutant::Mutator, 'def' do # Remove all statements mutations << 'def foo; end' + + mutations << 'def foo; raise; end' end it_should_behave_like 'a mutator' @@ -58,7 +60,7 @@ describe Mutant::Mutator, 'def' do mutations << 'def foo(a, srandom); end' # Mutation of body - mutations << 'def foo(a, b); ::Object.new; end' + mutations << 'def foo(a, b); raise; end' end it_should_behave_like 'a mutator' @@ -69,7 +71,7 @@ describe Mutant::Mutator, 'def' do let(:mutations) do mutations = [] - mutations << 'def foo(_unused); ::Object.new; end' + mutations << 'def foo(_unused); raise; end' mutations << 'def foo; end' end @@ -90,7 +92,7 @@ describe Mutant::Mutator, 'def' do mutations << 'def foo(a = false); end' mutations << 'def foo(a = nil); end' mutations << 'def foo(srandom = true); end' - mutations << 'def foo(a = true); ::Object.new; end' + mutations << 'def foo(a = true); raise; end' end it_should_behave_like 'a mutator' @@ -114,6 +116,8 @@ describe Mutant::Mutator, 'def' do # Remove all statements mutations << 'def self.foo; end' + + mutations << 'def self.foo; raise; end' end it_should_behave_like 'a mutator' @@ -125,24 +129,24 @@ describe Mutant::Mutator, 'def' do Mutant::Random.stub(:hex_string => 'random') end - let(:source) { 'def self.foo(a, b); nil; end' } + let(:source) { 'def self.foo(a, b); end' } let(:mutations) do mutations = [] # Deletion of each argument - mutations << 'def self.foo(a); nil; end' - mutations << 'def self.foo(b); nil; end' + mutations << 'def self.foo(a); end' + mutations << 'def self.foo(b); end' # Deletion of all arguments - mutations << 'def self.foo; nil; end' + mutations << 'def self.foo; end' # Rename each argument - mutations << 'def self.foo(srandom, b); nil; end' - mutations << 'def self.foo(a, srandom); nil; end' + mutations << 'def self.foo(srandom, b); end' + mutations << 'def self.foo(a, srandom); end' # Mutation of body - mutations << 'def self.foo(a, b); ::Object.new; end' + mutations << 'def self.foo(a, b); raise; end' end it_should_behave_like 'a mutator'