forked from mojombo/grit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_git.rb
84 lines (68 loc) · 2.55 KB
/
test_git.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require File.dirname(__FILE__) + '/helper'
class TestGit < Test::Unit::TestCase
def setup
@git = Git.new(File.join(File.dirname(__FILE__), *%w[..]))
end
def teardown
Grit.debug = false
end
def test_method_missing
assert_match(/^git version [\w\.]*$/, @git.version)
end
def test_logs_stderr
Grit.debug = true
Grit.stubs(:log)
Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
@git.bad
end
def testl_logs_stderr_when_skipping_timeout
Grit.debug = true
Grit.stubs(:log)
Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
@git.bad :timeout => false
end
def test_transform_options
assert_equal ["-s"], @git.transform_options({:s => true})
assert_equal ["-s '5'"], @git.transform_options({:s => 5})
assert_equal ["--max-count"], @git.transform_options({:max_count => true})
assert_equal ["--max-count='5'"], @git.transform_options({:max_count => 5})
assert_equal ["-s", "-t"], @git.transform_options({:s => true, :t => true}).sort
end
def test_uses_custom_sh_method
@git.expects(:sh)
@git.something
end
def test_can_skip_timeout
@git.expects(:wild_sh)
@git.something(:timeout => false)
end
def test_raises_if_too_many_bytes
@git.instance_variable_set(:@bytes_read, 6000000)
assert_raises Grit::Git::GitTimeout do
@git.version
end
end
def test_raises_on_slow_shell
Grit::Git.git_timeout = 0.0000001
assert_raises Grit::Git::GitTimeout do
@git.version
end
Grit::Git.git_timeout = 5.0
end
def test_it_really_shell_escapes_arguments_to_the_git_shell
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' foo --bar='bazz\\'er'")
@git.foo(:bar => "bazz'er")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' bar -x 'quu\\'x'")
@git.bar(:x => "quu'x")
end
def test_it_shell_escapes_the_standalone_argument
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' foo 'bar\\'s'")
@git.foo({}, "bar's")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' foo 'bar' '\\; echo \\'noooo\\''")
@git.foo({}, "bar", "; echo 'noooo'")
end
def test_piping_should_work_on_1_9
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' archive 'master' | gzip")
@git.archive({}, "master", "| gzip")
end
end