Sha256: 91a5da74f2fb412e1c6aa09e844c1412eb793f41b202cd875b1dbf6ad2faad5d

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Lolcommits
  module TestHelpers
    module GitRepo
      def repo
        @repo ||= Git.open(repo_path)
      end

      def repo_path
        '~/.lolcommits/plugin-test-repo'
      end

      def repo_exists?
        File.directory?(File.expand_path(repo_path, '.git'))
      end

      def last_commit
        repo.log.first
      end

      def setup_repo
        return if repo_exists?

        `git init --quiet #{repo_path}`
      end

      def commit_repo_with_message(message = 'test message', file_name: 'test.txt', file_content: 'testing')
        setup_repo unless repo_exists?
        `echo '#{file_content}' >> #{repo_path}/#{file_name}`
        `cd #{repo_path} && git add #{file_name}`
        `cd #{repo_path} && git commit -m "#{message}"`
      end

      def in_repo(&block)
        return unless repo_exists?

        Dir.chdir(File.expand_path(repo_path)) do
          yield block
        end
      end

      def teardown_repo
        `rm -rf #{repo_path}`
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lolcommits-0.17.1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.17.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.16.5 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.16.4 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.16.3 lib/lolcommits/test_helpers/git_repo.rb