Sha256: 3eb322045ce4f0285a482b81319a3d88fb8516ef094b34a1ec50c7144a351f48

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe Phare::Git do
  let(:extensions) { ['.rb'] }
  let(:options) { { diff: true } }
  let(:git) { described_class.new(extensions, options) }

  describe :changed? do
    context 'with --diff options' do
      before { expect(git).to receive(:changes).and_return(changes) }

      context 'with changes' do
        let(:changes) { ['foo.rb'] }

        it { expect(git.changed?).to eq(true) }
      end

      context 'without changes' do
        let(:changes) { [] }

        it { expect(git.changed?).to eq(false) }
      end
    end

    context 'without --diff options' do
      let(:options) { { diff: false } }

      it { expect(git.changed?).to eq(false) }
    end
  end

  describe :changes do
    before { expect(Phare).to receive(:system_output).with('git status -s').and_return(tree) }

    context 'with empty tree' do
      let(:tree) { '' }

      it { expect(git.changes).to eq([]) }
    end

    context 'with untracked file' do
      let(:tree) { "?? foo.rb" }

      it { expect(git.changes).to eq(['foo.rb']) }
    end

    context 'with added file' do
      let(:tree) { "A  foo.rb\nAM bar.rb" }

      it { expect(git.changes).to eq(['foo.rb', 'bar.rb']) }
    end

    context 'with modified file' do
      let(:tree) { "M  foo.rb\nDM bar.rb" }

      it { expect(git.changes).to eq(['foo.rb']) }
    end

    context 'with deleted file' do
      let(:tree) { " D foo.rb\nMD bar.rb" }

      it { expect(git.changes).to eq([]) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phare-0.5.2 spec/phare/git_spec.rb
phare-0.5.1 spec/phare/git_spec.rb