require 'spec_helper'

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

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

    it { should warn }
  end

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

    it { should pass }
  end

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

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

    before do
      result.stub(:success? => success, :stdout => 'Bundler error message')
      subject.stub(:execute).and_call_original
      subject.stub(:execute).with(%w[bundle check]).and_return(result)
    end

    context 'and bundle check exits unsuccessfully' do
      let(:success) { false }

      it { should fail_hook }
    end

    context 'and bundle check exist successfully' do
      let(:success) { true }

      it { should pass }
    end
  end
end

require 'spec_helper'

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

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

    it { should warn }
  end

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

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

      it { should pass }
    end

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

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

      before do
        result.stub(:success? => success, :stdout => 'Bundler error message')
        subject.stub(:execute).and_call_original
        subject.stub(:execute).with(%w[bundle check]).and_return(result)
      end

      context 'and bundle check exits unsuccessfully' do
        let(:success) { false }

        it { should fail_hook }
      end

      context 'and bundle check exist successfully' do
        let(:success) { true }

        it { should pass }
      end
    end
  end
end

Fix BundleCheck spec to stub in_path?
Fix BundleCheck spec to stub in_path?

This spec didn't stub the call to `in_path?` when it should have. It
worked because `bundler` is installed on Travis, but it is better form
to not make that assumption.

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