Sha256: cd4f3241fd2966d7ceb36e45c4e9d7d3750b6c8a57696e52d899945b73b61d90

Contents?: true

Size: 999 Bytes

Versions: 9

Compression:

Stored size: 999 Bytes

Contents

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

9 entries across 9 versions & 1 rubygems

Version Path
lolcommits-0.12.1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.12.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.11.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.11.0.pre lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.10.0 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.10.0.pre1 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.8 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.7 lib/lolcommits/test_helpers/git_repo.rb
lolcommits-0.9.7.pre1 lib/lolcommits/test_helpers/git_repo.rb