Split differ interface and mutation cover Mutant::Differ.build

This commit is contained in:
Markus Schirp 2013-07-02 20:10:59 +02:00
parent d4b94fc8f4
commit e5333b9980
4 changed files with 21 additions and 9 deletions

View file

@ -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

View file

@ -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?

View file

@ -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

View file

@ -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") }