Sha256: 0de40c2cef453c1960d3f7092bbf26df20f535a73c0aec3da3b8d5093d178810

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

# encoding: utf-8
describe PreReceiveHookParser do
  let(:git_repo) { 'git_repo' }

  context '#initialize' do
    it 'expects three values old_sha, new_sha, ref_name' do
      PreReceiveHookParser.new('f5cb631e8b09444107408ad63c0fba13aaa23d18 76bc1a95fe094be30f7d77c9d374b0329b140ee9 /ref')
    end
  end

  context '#files' do
    it 'returns files for commit' do
      git_init(git_repo)

      create_file(File.join(git_repo, 'file.txt'))
      git_add(git_repo, 'file.txt')
      git_commit(git_repo)

      create_file(File.join(git_repo, 'file1.txt'), 'content file1')
      create_file(File.join(git_repo, 'file2.txt'), 'content file2')
      git_add(git_repo, 'file1.txt')
      git_add(git_repo, 'file2.txt')

      git_commit(git_repo)

      commit = git_show(git_repo, nil).first.split(" ")[1]

      Dir.chdir(::File.join(working_directory, git_repo)) do
        parser = PreReceiveHookParser.new("#{commit}^ #{commit} /ref/asdf/asdf")
        expect(parser.files.collect { |f| f.name }).to eq(%w{file1.txt file2.txt})
      end
    end

    it 'returns files for root commit' do
      git_init(git_repo)

      create_file(File.join(git_repo, 'file.txt'))
      git_add(git_repo, 'file.txt')
      git_commit(git_repo)

      commit = git_show(git_repo, nil).first.split(" ")[1]

      Dir.chdir(::File.join(working_directory, git_repo)) do
        parser = PreReceiveHookParser.new("#{'0' * 40} #{commit} /ref/asdf/asdf")
        expect(parser.files.collect { |f| f.name }).to eq(%w{file.txt})
      end
    end

    it 'returns files in directories' do
      git_init(git_repo)

      create_file(File.join(git_repo, 'dir/file.txt'))
      git_add(git_repo, 'dir/file.txt')
      git_commit(git_repo)

      commit = git_show(git_repo, nil).first.split(" ")[1]

      Dir.chdir(::File.join(working_directory, git_repo)) do
        parser = PreReceiveHookParser.new("#{'0' * 40} #{commit} /ref/asdf/asdf")
        expect(parser.files.collect { |f| f.name }).to eq(%w{dir/file.txt})
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_hook-pre_receive-0.0.2 spec/pre_receive_hook_parser_spec.rb