Sha256: 8da230dd8b3b05ade9d44df4947f7643041424b37a526f442f4dbb9998aecf2b

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Phare::Git do
  let(:described_class) { Phare::Git }

  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) { %w(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 be_empty }
    end

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

      it { expect(git.changes).to be_empty }
    end

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

      it { expect(git.changes).to match_array(%w(foo.rb bar.rb)) }
    end

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

      it { expect(git.changes).to match_array(%w(foo.rb)) }
    end

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

      it { expect(git.changes).to match_array(%w(bar.rb)) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
phare-1.0.1 spec/phare/git_spec.rb
phare-1.0.0 spec/phare/git_spec.rb
phare-0.7.1 spec/phare/git_spec.rb
phare-0.7 spec/phare/git_spec.rb