require 'spec_helper'

describe Overcommit::Hook::PreCommit::BerksfileCheck do
  let(:config)  { Overcommit::ConfigurationLoader.default_configuration }
  let(:context) { double('context') }
  subject { described_class.new(config, context) }

  context 'when Berkshelf is not installed' do
    before do
      subject.stub(:in_path?).and_return(false)
    end

    it { should warn }
  end

  context 'when Berksfile.lock is ignored' do
    around do |example|
      repo do
        `touch Berksfile.lock`
        `echo Berksfile.lock > .gitignore`
        `git add .gitignore`
        `git commit -m "Ignore Berksfile.lock"`
        example.run
      end
    end

    it { should pass }
  end

  context 'when Berksfile.lock is not ignored' do
    let(:result) { double('result') }

    around do |example|
      repo do
        example.run
      end
    end

    before do
      result.stub(:success? => success, :stderr => 'Berkshelf error message')
      subject.stub(:execute).and_call_original
      subject.stub(:execute).with(%w[berks list --quiet]).and_return(result)
    end

    context 'and `berks list` exits unsuccessfully' do
      let(:success) { false }

      it { should fail_hook }
    end

    context 'and `berks list` exits successfully' do
      let(:success) { true }

      it { should pass }
    end
  end
end

require 'spec_helper'

describe Overcommit::Hook::PreCommit::BerksfileCheck do
  let(:config)  { Overcommit::ConfigurationLoader.default_configuration }
  let(:context) { double('context') }
  subject { described_class.new(config, context) }

  context 'when Berkshelf is not installed' do
    before do
      subject.stub(:in_path?).and_return(false)
    end

    it { should warn }
  end

  context 'when Berkshelf is installed' do
    before do
      subject.stub(:in_path?).and_return(true)
    end

    context 'when Berksfile.lock is ignored' do
      around do |example|
        repo do
          `touch Berksfile.lock`
          `echo Berksfile.lock > .gitignore`
          `git add .gitignore`
          `git commit -m "Ignore Berksfile.lock"`
          example.run
        end
      end

      it { should pass }
    end

    context 'when Berksfile.lock is not ignored' do
      let(:result) { double('result') }

      around do |example|
        repo do
          example.run
        end
      end

      before do
        result.stub(:success? => success, :stderr => 'Berkshelf error message')
        subject.stub(:execute).and_call_original
        subject.stub(:execute).with(%w[berks list --quiet]).and_return(result)
      end

      context 'and `berks list` exits unsuccessfully' do
        let(:success) { false }

        it { should fail_hook }
      end

      context 'and `berks list` exits successfully' do
        let(:success) { true }

        it { should pass }
      end
    end
  end
end

Fix BerksfileCheck spec to stub in_path?
Fix BerksfileCheck spec to stub in_path?

This spec would pass locally but fail on Travis because it didn't stub
the `in_path?` call. Fix it.

Change-Id: I359f69518eae2f108761c6e48f2273a9b8cc146e
Reviewed-on: http://gerrit.causes.com/37940
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@causes.com>
Reviewed-by: Shane da Silva <6f6e68d1df92f30cb4b3ce35260ddf94a402f33d@causes.com>
