Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding test_helpers for plugin testing
- Loading branch information
1 parent
d9ae213
commit c59af6f
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |