Sha256: f3f08c7453d17bb25e55ac6687180f952af052d8d23d9cc789985070a984eb43

Contents?: true

Size: 1.16 KB

Versions: 107

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/envs'
require 'eac_launcher/git/base'
require 'fileutils'
require 'tmpdir'

module Avm
  module Git
    module SpecHelper
      def stubbed_git_repository(bare = false)
        path = ::Dir.mktmpdir
        ::EacRubyUtils::Envs.local.command(stubbed_git_repository_args(path, bare)).execute!
        StubbedGitRepository.new(path)
      end

      private

      def stubbed_git_repository_args(path, bare)
        r = %w[git init]
        r << '--bare' if bare
        r + [path]
      end

      class StubbedGitRepository < ::EacLauncher::Git::Base
        def file(*subpath)
          StubbedGitRepositoryFile.new(self, subpath)
        end
      end

      class StubbedGitRepositoryFile
        attr_reader :git, :subpath

        def initialize(git, subpath)
          @git = git
          @subpath = subpath
        end

        def path
          ::File.join(git, *subpath)
        end

        def touch
          ::FileUtils.touch(path)
        end

        def delete
          ::File.unlink(path)
        end

        def write(content)
          ::File.write(path, content)
        end
      end
    end
  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
avm-tools-0.94.2 lib/avm/git/spec_helper.rb
avm-tools-0.94.1 lib/avm/git/spec_helper.rb
avm-tools-0.94.0 lib/avm/git/spec_helper.rb
avm-tools-0.93.0 lib/avm/git/spec_helper.rb
avm-tools-0.92.0 lib/avm/git/spec_helper.rb
avm-tools-0.91.0 lib/avm/git/spec_helper.rb
avm-tools-0.90.0 lib/avm/git/spec_helper.rb
avm-tools-0.89.0 lib/avm/git/spec_helper.rb
avm-tools-0.88.0 lib/avm/git/spec_helper.rb
avm-tools-0.87.1 lib/avm/git/spec_helper.rb
avm-tools-0.87.0 lib/avm/git/spec_helper.rb
avm-tools-0.86.0 lib/avm/git/spec_helper.rb
avm-tools-0.85.1 lib/avm/git/spec_helper.rb
avm-tools-0.85.0 lib/avm/git/spec_helper.rb
avm-tools-0.84.0 lib/avm/git/spec_helper.rb
avm-tools-0.83.0 lib/avm/git/spec_helper.rb
avm-tools-0.82.1 lib/avm/git/spec_helper.rb
avm-tools-0.82.0 lib/avm/git/spec_helper.rb
avm-tools-0.81.0 lib/avm/git/spec_helper.rb
avm-tools-0.80.0 lib/avm/git/spec_helper.rb