From 681b51f6ac8000ede35db6ee19de899a7ca66383 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 30 Oct 2013 09:06:39 +0100 Subject: [PATCH] Fix multiple diff reporter errors on memoizers Closes #130 --- lib/mutant/subject/method/instance.rb | 11 ++++++ .../mutant/subject/method/instance_spec.rb | 35 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 spec/unit/mutant/subject/method/instance_spec.rb diff --git a/lib/mutant/subject/method/instance.rb b/lib/mutant/subject/method/instance.rb index d31f6e7d..d2be41f0 100644 --- a/lib/mutant/subject/method/instance.rb +++ b/lib/mutant/subject/method/instance.rb @@ -30,6 +30,17 @@ module Mutant class Memoized < self include NodeHelpers + # Return source + # + # @return [String] + # + # @api private + # + def source + Unparser.unparse(memoizer_node(node)) + end + memoize :source + private # Return mutations diff --git a/spec/unit/mutant/subject/method/instance_spec.rb b/spec/unit/mutant/subject/method/instance_spec.rb new file mode 100644 index 00000000..2eb1cae3 --- /dev/null +++ b/spec/unit/mutant/subject/method/instance_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe Mutant::Subject::Method::Instance do + include Mutant::NodeHelpers + + let(:object) { described_class.new(context, node) } + let(:context) { double } + + let(:node) do + s(:def, :foo, s(:args)) + end + + describe '#source' do + subject { object.source } + + it { should eql("def foo\nend") } + end +end + +describe Mutant::Subject::Method::Instance::Memoized do + include Mutant::NodeHelpers + + let(:object) { described_class.new(context, node) } + let(:context) { double } + + let(:node) do + s(:def, :foo, s(:args)) + end + + describe '#source' do + subject { object.source } + + it { should eql("def foo\nend\nmemoize(:foo)") } + end +end