Sha256: 6816287e381e75eccee55c46d376bd55e1333751592abc35920fecc7d4a4b156

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Dandelion::Changeset do
  context 'empty local path' do
    let(:changeset) { test_changeset }

    describe '#enumerable' do
      let(:changes) { changeset.to_a }

      it 'returns all changes' do
        expect(changes).to be_a(Array)
        expect(changes.length).to eq 5
        expect(changes.map(&:path)).to eq ['bar', 'baz/foo', 'baz/bar', 'foo', 'qux']
        expect(changes.map(&:type)).to eq [:delete, :delete, :write, :write, :write]
      end

      it 'returns data for write changes' do
        expect(changes.select { |c| c.type == :write }.map(&:data)).to eq ["bar\n", "foo\n", ""]
      end
    end

    describe '#empty?' do
      it 'returns false' do
        expect(changeset.empty?).to eq false
      end
    end
  end

  context 'non-empty local path' do
    let(:changeset) { test_changeset(local_path: './baz') }

    describe '#enumerable' do
      let(:changes) { changeset.to_a }

      it 'returns all changes' do
        expect(changes).to be_a(Array)
        expect(changes.length).to eq 2
        expect(changes.map(&:path)).to eq ['foo', 'bar']
        expect(changes.map(&:type)).to eq [:delete, :write]
      end

      it 'returns data for write changes' do
        expect(changes.last.data).to eq "bar\n"
      end
    end

    describe '#empty?' do
      it 'returns false' do
        expect(changeset.empty?).to eq false
      end
    end
  end

  context 'empty diff' do
    let(:changeset) { test_changeset }
    before(:each) { allow(changeset).to receive(:diff) { [] } }

    describe '#enumerable' do
      let(:changes) { changeset.to_a }

      it 'returns no changes' do
        expect(changes).to be_a(Array)
        expect(changes.length).to eq 0
      end
    end

    describe '#empty?' do
      it 'returns true' do
        expect(changeset.empty?).to eq true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dandelion-0.4.17 spec/dandelion/changeset_spec.rb