Sha256: d1ed32570dfdbf23bcc522cd152462f8ee6321938c4968a5c5b5f3b127f8e657

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 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
        return unless repo_exists?

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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
lolcommits-0.16.2 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.16.1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.16.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.16.0.pre1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.15.1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.15.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.14.2 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.14.1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.14.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.13.1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.13.0 lib/lolcommits/test_helpers/git_repo.rb