Sha256: c5b18ea5c32e1cd9121f4a4edbf5a50a523256847049ff59666966a7813f8086

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe SuperHooks::Installer::Global do
  describe '#run' do
    let(:runner) { described_class.new }
    let(:home_dir) { Helpers::EmptyRepository.new(name: 'foo_test') }

    before :each do
      stub_const('ENV', ENV.to_hash.merge('HOME' => home_dir.path))
      stub_const('SuperHooks::Hook::LIST', %w(foo))

      allow(SuperHooks::Git).to receive(:command).with(anything).and_return(nil)
    end

    after :each do
      home_dir.remove
    end

    context 'templates already exists' do
      before :each do
        expect(File).to receive(:exist?).with("#{ENV['HOME']}/.git_global_templates").and_return(true)
      end

      it 'does not create them' do
        expect(FileUtils).to receive(:mkdir_p).never
        expect(File).to receive(:open).never
        expect(SuperHooks::Git).to receive(:command).with("config --global init.templatedir #{ENV['HOME']}/.git_global_templates")
        runner.run
      end
    end

    context 'templates do not exist' do
      before :each do
        expect(File).to receive(:exist?).with("#{ENV['HOME']}/.git_global_templates").and_return(false)
      end

      it 'creates them' do
        file = double('file')
        expect(FileUtils).to receive(:mkdir_p).once.and_return(double.as_null_object)
        expect(File).to receive(:open).with("#{ENV['HOME']}/.git_global_templates/hooks/foo", 'w', 0755).once.and_yield(file)
        expect(file).to receive(:write).with(anything)
        runner.run
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
super_hooks-0.0.2.1 spec/lib/super_hooks/global_installer_spec.rb