From 82634f383cfcce5779e61209154f1553fd5e514b Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 11 May 2014 14:38:07 +0000 Subject: [PATCH] Do not present un idempotent interface on abstract class --- lib/mutant.rb | 2 +- lib/mutant/mutation.rb | 3 ++- lib/mutant/mutation/evil.rb | 12 +----------- lib/mutant/mutation/neutral.rb | 11 ----------- spec/unit/mutant/mutation_spec.rb | 13 ++++++++----- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/lib/mutant.rb b/lib/mutant.rb index 7ddad439..917a795b 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -61,7 +61,7 @@ module Mutant begin data = Marshal.load(reader.read) - rescue ArgumentError => exception + rescue ArgumentError raise IsolationError, 'Childprocess wrote unmarshallable data' end diff --git a/lib/mutant/mutation.rb b/lib/mutant/mutation.rb index b6b62256..9bcd443b 100644 --- a/lib/mutant/mutation.rb +++ b/lib/mutant/mutation.rb @@ -57,8 +57,9 @@ module Mutant # @api private # def identification - "#{subject.identification}:#{code}" + "#{self.class::SYMBOL}:#{subject.identification}:#{code}" end + memoize :identification # Return mutation code # diff --git a/lib/mutant/mutation/evil.rb b/lib/mutant/mutation/evil.rb index d56711c5..a4d2b6bf 100644 --- a/lib/mutant/mutation/evil.rb +++ b/lib/mutant/mutation/evil.rb @@ -6,17 +6,7 @@ module Mutant class Evil < self SHOULD_FAIL = true - - # Return identification - # - # @return [String] - # - # @api private - # - def identification - "evil:#{super}" - end - memoize :identification + SYMBOL = 'evil'.freeze # Test if killer is successful # diff --git a/lib/mutant/mutation/neutral.rb b/lib/mutant/mutation/neutral.rb index 0fff82e0..54b0f80c 100644 --- a/lib/mutant/mutation/neutral.rb +++ b/lib/mutant/mutation/neutral.rb @@ -15,17 +15,6 @@ module Mutant end # Noop - # Return identification - # - # @return [String] - # - # @api private - # - def identification - "#{self.class::SYMBOL}:#{super}" - end - memoize :identification - end # Neutral end # Mutation end # Mutant diff --git a/spec/unit/mutant/mutation_spec.rb b/spec/unit/mutant/mutation_spec.rb index fac8bf2b..8ae7a09a 100644 --- a/spec/unit/mutant/mutation_spec.rb +++ b/spec/unit/mutant/mutation_spec.rb @@ -4,10 +4,13 @@ require 'spec_helper' describe Mutant::Mutation do - let(:class_under_test) { Class.new(described_class) { memoize :identification } } - let(:object) { class_under_test.new(mutation_subject, Mutant::NodeHelpers::N_NIL) } - let(:mutation_subject) { double('Subject', identification: 'subject', source: 'original') } - let(:node) { double('Node') } + class TestMutation < Mutant::Mutation + SYMBOL = 'test' + end + + let(:object) { TestMutation.new(mutation_subject, Mutant::NodeHelpers::N_NIL) } + let(:mutation_subject) { double('Subject', identification: 'subject', source: 'original') } + let(:node) { double('Node') } describe '#code' do subject { object.code } @@ -37,7 +40,7 @@ describe Mutant::Mutation do subject { object.identification } - it { should eql('subject:8771a') } + it { should eql('test:subject:8771a') } it_should_behave_like 'an idempotent method' end