diff --git a/lib/mutant/differ.rb b/lib/mutant/differ.rb index 660c48f2..1eef1a08 100644 --- a/lib/mutant/differ.rb +++ b/lib/mutant/differ.rb @@ -45,8 +45,8 @@ module Mutant # # @api private # - def self.new(old, new) - super(lines(old), lines(new)) + def self.build(old, new) + new(lines(old), lines(new)) end private diff --git a/lib/mutant/reporter/cli/printer/mutation.rb b/lib/mutant/reporter/cli/printer/mutation.rb index 86b775fd..7649879b 100644 --- a/lib/mutant/reporter/cli/printer/mutation.rb +++ b/lib/mutant/reporter/cli/printer/mutation.rb @@ -38,7 +38,7 @@ module Mutant # def colorized_diff original, current = mutation.original_source, mutation.source - differ = Differ.new(original, current) + differ = Differ.build(original, current) diff = color? ? differ.colorized_diff : differ.diff if diff.empty? diff --git a/spec/unit/mutant/differ/class_methods/build_spec.rb b/spec/unit/mutant/differ/class_methods/build_spec.rb new file mode 100644 index 00000000..5679c8d4 --- /dev/null +++ b/spec/unit/mutant/differ/class_methods/build_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Mutant::Differ, '.build' do + let(:object) { described_class } + + subject { object.build(old_string, new_string) } + + let(:old_string) { "foo\nbar" } + let(:new_string) { "bar\nbaz" } + + it { should eql(Mutant::Differ.new(%w(foo bar), %w(bar baz))) } +end diff --git a/spec/unit/mutant/differ/diff_spec.rb b/spec/unit/mutant/differ/diff_spec.rb index e3ae4917..9c5a3fb0 100644 --- a/spec/unit/mutant/differ/diff_spec.rb +++ b/spec/unit/mutant/differ/diff_spec.rb @@ -5,18 +5,18 @@ describe Mutant::Differ, '#diff' do subject { object.diff } - context 'when there is a diff that is at beginning of hunk' do - let(:old) { "foo\nbar" } - let(:new) { "baz\nbar" } + context 'when there is a diff at beginning of hunk' do + let(:old) { %w(foo bar) } + let(:new) { %w(baz bar) } it { should eql("@@ -1,3 +1,3 @@\n-foo\n+baz\n bar\n") } it_should_behave_like 'an idempotent method' end - context 'when there is a diff that is NOT at beginning of hunk' do - let(:old) { "foo\nbar" } - let(:new) { "foo\nbaz\nbar" } + context 'when there is a diff NOT at beginning of hunk' do + let(:old) { %w(foo bar) } + let(:new) { %w(foo baz bar) } it { should eql("@@ -1,3 +1,4 @@\n foo\n+baz\n bar\n") }