Sha256: 2cc250eef7ef1c52f658fb955ff0920098466a2683610675e10d0eb7c079c98c

Contents?: true

Size: 1.66 KB

Versions: 8

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

describe Mutant::Differ, '#diff' do
  let(:object) { described_class.new(old, new) }

  subject { object.diff }

  context 'when there is a diff at begin 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 NOT at begin 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") }

    it_should_behave_like 'an idempotent method'
  end

  context 'when the diff has a long context at begin' do
    let(:old) { %w(foo bar baz boz a b c)       }
    let(:new) { %w(foo bar baz boz a b c other) }

    it { should eql("@@ -1,8 +1,9 @@\n foo\n bar\n baz\n boz\n a\n b\n c\n+other\n") }

    it_should_behave_like 'an idempotent method'
  end

  context 'when the diff has a long context at end, deleting' do
    let(:old) { %w(other foo bar baz boz a b c) }
    let(:new) { %w(foo bar baz boz a b c)       }

    it { should eql("@@ -1,9 +1,8 @@\n-other\n foo\n bar\n baz\n boz\n a\n b\n c\n") }

    it_should_behave_like 'an idempotent method'
  end

  context 'when the diff has a long context at end, inserting' do
    let(:old) { %w(foo bar baz boz a b c)       }
    let(:new) { %w(other foo bar baz boz a b c) }

    it { should eql("@@ -1,8 +1,9 @@\n+other\n foo\n bar\n baz\n boz\n a\n b\n c\n") }

    it_should_behave_like 'an idempotent method'
  end

  context 'when there is no diff' do
    let(:old) { '' }
    let(:new) { '' }

    it { should be(nil) }

    it_should_behave_like 'an idempotent method'
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.3.0.beta21 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta20 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta19 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta18 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta17 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta16 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta15 spec/unit/mutant/differ/diff_spec.rb
mutant-0.3.0.beta14 spec/unit/mutant/differ/diff_spec.rb