Sha256: ba6220d0a56af81f415897672c1647a229489991d562c1ffe0941c4980a90ffa

Contents?: true

Size: 1.3 KB

Versions: 28

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'eac_git/local'
require 'eac_ruby_utils/envs'
require 'fileutils'
require 'tmpdir'

module EacGit
  module Rspec
    module StubbedGitLocalRepo
      def stubbed_git_local_repo(bare = false)
        path = ::Dir.mktmpdir
        ::EacRubyUtils::Envs.local.command(stubbed_git_local_repo_args(path, bare)).execute!
        repo = StubbedGitRepository.new(path)
        repo.command('config', 'user.email', 'theuser@example.net').execute!
        repo.command('config', 'user.name', 'The User').execute!
        repo
      end

      private

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

      class StubbedGitRepository < ::EacGit::Local
        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
          git.root_path.join(*subpath)
        end

        def touch
          ::FileUtils.touch(path.to_path)
        end

        def delete
          path.unlink
        end

        def write(content)
          path.write(content)
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
avm-tools-0.108.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.107.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.8.0 lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.106.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.105.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.7.3 lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.7.2 lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.7.1 lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.7.0 lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.104.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.103.1 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.103.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.102.2 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.6.0 lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.102.1 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.102.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
eac_git-0.5.0 lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.101.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.100.0 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb
avm-tools-0.99.1 vendor/eac_git/lib/eac_git/rspec/stubbed_git_local_repo.rb