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(&block) ⇒ 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
28 29 30 31 32 33 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 28 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 "#{}"` end |
#in_repo(&block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 35 def in_repo(&block) return unless repo_exists? Dir.chdir(File.(repo_path)) do yield block end end |
#last_commit ⇒ Object
18 19 20 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 18 def last_commit repo.log.first end |
#repo ⇒ Object
6 7 8 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 6 def repo @repo ||= Git.open(repo_path) end |
#repo_exists? ⇒ Boolean
14 15 16 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 14 def repo_exists? File.directory?(File.(repo_path, '.git')) end |
#repo_path ⇒ Object
10 11 12 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 10 def repo_path '/tmp/lolcommits-plugin-test-repo' end |
#setup_repo ⇒ Object
22 23 24 25 26 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 22 def setup_repo return if repo_exists? `git init --quiet #{repo_path}` end |
#teardown_repo ⇒ Object
43 44 45 |
# File 'lib/lolcommits/test_helpers/git_repo.rb', line 43 def teardown_repo `rm -rf #{repo_path}` end |