Sha256: c648f447233f0ceaa5ee9b3779cbeef79dc599ae8907b31fabe946b0df400d59

Contents?: true

Size: 1006 Bytes

Versions: 9

Compression:

Stored size: 1006 Bytes

Contents

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

      def repo_path
        '~/.lolcommits/sample-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

9 entries across 9 versions & 1 rubygems

Version Path
lolcommits-0.9.6 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.5 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.5.pre1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.4 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.4.pre1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.3 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.3.pre3 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.3.pre2 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.3.pre1 lib/lolcommits/test_helpers/git_repo.rb