forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_spec_helpers.rb
38 lines (31 loc) · 1.02 KB
/
git_spec_helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'tmpdir'
# Helpers for creating temporary repositories and directories for testing.
module GitSpecHelpers
module_function
def repo(options = {}, &block)
directory('some-repo') do
`git init --template="#{options[:template_dir]}"`
# Need to define user info since some CI contexts don't have defaults set
`git config --local user.name "Overcommit Tester"`
`git config --local user.email "overcommit@example.com"`
`git config --local rerere.enabled 0` # Don't record resolutions in tests
block.call if block_given?
end
end
# Creates a directory (with an optional specific name) in a temporary
# directory which will automatically be destroyed.
def directory(name = 'some-dir', &block)
tmpdir = Dir.mktmpdir.tap do |path|
Dir.chdir(path) do
Dir.mkdir(name)
Dir.chdir(name) do
block.call if block_given?
end
end
end
File.join(tmpdir, name)
end
def random_hash
40.times.map { (65 + rand(26)).chr }.join
end
end