Module: Lolcommits::TestHelpers::GitRepo
- Defined in:
- lib/lolcommits/test_helpers/git_repo.rb
Instance Method Summary collapse
- #commit_repo_with_message(message = 'test message', file_name: 'test.txt', file_content: 'testing') ⇒ Object
- #in_repo ⇒ Object
- #last_commit ⇒ Object
- #repo ⇒ Object
- #repo_exists? ⇒ Boolean
- #repo_path ⇒ Object
- #setup_repo ⇒ Object
- #teardown_repo ⇒ Object
Instance Method Details
#commit_repo_with_message(message = 'test message', file_name: 'test.txt', file_content: 'testing') ⇒ Object
25 26 27 28 29 30 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 25 def ( = '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 |
#in_repo ⇒ Object
32 33 34 35 36 37 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 32 def in_repo return unless repo_exists? Dir.chdir(File.(repo_path)) do yield end end |
#last_commit ⇒ Object
16 17 18 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 16 def last_commit repo.log.first end |
#repo ⇒ Object
4 5 6 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 4 def repo @repo ||= Git.open(repo_path) end |
#repo_exists? ⇒ Boolean
12 13 14 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 12 def repo_exists? File.directory?(File.(repo_path, '.git')) end |
#repo_path ⇒ Object
8 9 10 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 8 def repo_path '~/.lolcommits/sample-plugin-test-repo' end |
#setup_repo ⇒ Object
20 21 22 23 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 20 def setup_repo return if repo_exists? `git init --quiet #{repo_path}` end |
#teardown_repo ⇒ Object
39 40 41 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 39 def teardown_repo `rm -rf #{repo_path}` end |