From a06030ef069b2858ee310b560a4da4c5c159a169 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sat, 29 Dec 2012 22:51:42 +0100 Subject: [PATCH] Take care to not mutate `self.class` into `class` --- lib/mutant/mutator/node/send.rb | 26 +++++++++++++++---- .../mutant/mutator/node/send/mutation_spec.rb | 11 ++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/mutant/mutator/node/send.rb b/lib/mutant/mutator/node/send.rb index ea676953..69e8ada6 100644 --- a/lib/mutant/mutator/node/send.rb +++ b/lib/mutant/mutator/node/send.rb @@ -29,7 +29,7 @@ module Mutant # @api private # def emit_receiver - unless self? + unless to_self? emit(receiver) end end @@ -53,7 +53,7 @@ module Mutant # @api private # def emit_receiver_mutations - unless self? + unless to_self? or self_class? emit_attribute_mutations(:receiver) end end @@ -93,17 +93,33 @@ module Mutant # Check if receiver is self # # @return [true] - # returns true when receiver is a Rubinius::AST::Self node + # if receiver is a Rubinius::AST::Self node # # @return [false] # return false otherwise # # @api private # - def self? + def to_self? receiver.kind_of?(Rubinius::AST::Self) end + # Check if receiver is self.class + # + # @return [true] + # if receiver is a "self.class" construct + # + # @return [false] + # otherwise + # + # @api private + # + def self_class? + receiver.kind_of?(Rubinius::AST::Send) && + receiver.name == :class && + receiver.receiver.kind_of?(Rubinius::AST::Self) + end + # Emit mutation that replaces explicit send to self with implicit send to self # # @example: @@ -130,7 +146,7 @@ module Mutant # @api private # def emit_implicit_self_receiver - return unless self? + return unless to_self? mutant = dup_node mutant.privately = true # TODO: Fix rubinius to allow this as an attr_accessor diff --git a/spec/unit/mutant/mutator/node/send/mutation_spec.rb b/spec/unit/mutant/mutator/node/send/mutation_spec.rb index 21406c04..e418629c 100644 --- a/spec/unit/mutant/mutator/node/send/mutation_spec.rb +++ b/spec/unit/mutant/mutator/node/send/mutation_spec.rb @@ -32,6 +32,17 @@ describe Mutant::Mutator, 'send' do it_should_behave_like 'a mutator' end + + context 'to self.class.foo' do + let(:source) { 'self.class.foo' } + + let(:mutations) do + mutations = [] + mutations << 'self.class' + end + + it_should_behave_like 'a mutator' + end end context 'send with arguments' do