diff --git a/Changelog.md b/Changelog.md index d22b86e2..c64bdc92 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ * Add mutation from `a != b` to `!a.eql?(b)` and `!a.equal?(b)` #417 * Add mutation `A.const_get(:B)` -> `A::B` #426 * Add mutation `def foo(*args); end` into `def foo(*args); args = []; end` #423 +* Add mutation from `foo.baz { bar }` to `foo.bar` #416 # v0.8.3 2015-09-01 diff --git a/config/flay.yml b/config/flay.yml index 91ef8e86..961789d7 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1219 +total_score: 1223 diff --git a/lib/mutant/mutator/node/block.rb b/lib/mutant/mutator/node/block.rb index 286489d0..736c6cef 100644 --- a/lib/mutant/mutator/node/block.rb +++ b/lib/mutant/mutator/node/block.rb @@ -36,6 +36,22 @@ module Mutant return unless body emit(body) emit_body_mutations + + mutate_body_receiver + end + + # Mutate method send in body scope of `send` + # + # @return [undefined] + # + # @api private + def mutate_body_receiver + return unless n_send?(body) + + body_meta = AST::Meta::Send.new(body) + send_meta = AST::Meta::Send.new(send) + + emit(s(:send, send_meta.receiver, body_meta.selector, *body_meta.arguments)) end end # Block diff --git a/meta/block.rb b/meta/block.rb index 1e9d987b..0586028e 100644 --- a/meta/block.rb +++ b/meta/block.rb @@ -69,3 +69,18 @@ Mutant::Meta::Example.add do mutation 'foo { |(_a)| }' mutation 'foo' end + +Mutant::Meta::Example.add do + source 'self.foo { bar(nil) }' + + singleton_mutations + mutation 'self.foo' + mutation 'foo { bar(nil) }' + mutation 'self.foo { bar }' + mutation 'self.foo { nil }' + mutation 'self.foo {}' + mutation 'self.foo { self }' + mutation 'self.foo { raise }' + mutation 'bar(nil)' + mutation 'self.bar(nil)' +end