Skip to content

Commit

Permalink
adding test_helpers for plugin testing
Browse files Browse the repository at this point in the history
  • Loading branch information
matthutchinson committed Feb 13, 2017
1 parent d9ae213 commit c59af6f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/lolcommits/test_helpers/git_repo.rb
@@ -0,0 +1,44 @@
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

0 comments on commit c59af6f

Please sign in to comment.