Sha256: 3f5c5161b5ba320f18c624f3d1df585b4ee84d3705358cdf608aec82131e277d

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require File.expand_path('../../../lib/sub_diff/diff_collection', __FILE__)

RSpec.describe SubDiff::DiffCollection do
  subject { described_class.new(diffable) }

  let(:diffable) { 'this is a simple test' }

  describe '#changed?' do
    it 'should return true if any diffs have changed' do
      subject.push('one', 'two')
      expect(subject).to be_changed
    end

    it 'should return false if no diffs have changed' do
      subject.push('same', 'same')
      expect(subject).not_to be_changed
    end

    it 'should return false if there are no diffs' do
      expect(subject).not_to be_changed
    end
  end

  describe '#each' do
    it { is_expected.to be_an(Enumerable) }
    it { is_expected.to delegate(:each).to(:diffs) }
  end

  describe '#push' do
    it 'should return self' do
      expect(subject.push).to eq(subject)
    end

    it 'should append an unchanged diff' do
      block = proc { subject.push('unchanged') }
      expect(block).to change(subject.diffs, :size)
    end

    it 'should append a changed diff' do
      block = proc { subject.push('now', 'was') }
      expect(block).to change(subject.diffs, :size)
    end

    it 'should not append a nil diff' do
      block = proc { subject.push(nil) }
      expect(block).not_to change(subject.diffs, :size)
    end

    it 'should not append an empty diff' do
      block = proc { subject.push('') }
      expect(block).not_to change(subject.diffs, :size)
    end
  end

  describe '#size' do
    it { is_expected.to delegate(:size).to(:diffs) }

    it 'should not use the string size' do
      expect(subject.size).not_to eq(subject.to_s.size)
    end
  end

  describe '#__getobj__' do
    it 'should join the diff values if any' do
      subject.push('test')
      subject.push('example')
      expect(subject.__getobj__).to eq('testexample')
    end

    it 'should return the diffable if diffs are empty' do
      expect(subject.__getobj__).to eq(diffable)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sub_diff-1.0.0 spec/sub_diff/diff_collection_spec.rb