-
Notifications
You must be signed in to change notification settings - Fork 81
/
mercurial_spec.rb
124 lines (108 loc) · 5.03 KB
/
mercurial_spec.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require File.expand_path('../spec_helper', __FILE__)
module Pod
module Downloader
describe 'Mercurial' do
before do
tmp_folder.rmtree if tmp_folder.exist?
end
it 'checks out a specific revision' do
options = { :hg => fixture('mercurial-repo'), :revision => '46198bb3af96' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
tmp_folder('README').read.strip.should == 'first commit'
end
it 'checks out the head revision' do
options = { :hg => fixture('mercurial-repo') }
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
tmp_folder('README').read.strip.should == 'second commit'
end
it 'returns whether it supports the download of the head' do
options = { :hg => fixture('mercurial-repo') }
downloader = Downloader.for_target(tmp_folder('checkout'), options)
downloader.head_supported?.should.be.true
end
describe 'when the directory name has quotes or spaces' do
it 'checks out a specific revision' do
options = { :hg => fixture('mercurial-repo'), :revision => '46198bb3af96' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'first commit'
end
it 'checks out the head revision' do
options = { :hg => fixture('mercurial-repo') }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'second commit'
end
it 'checks out a specific tag' do
options = { :hg => fixture('mercurial-repo'), :tag => '1.0.0' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'third commit'
end
it 'checks out the branch head revision' do
options = { :hg => fixture('mercurial-repo'), :branch => 'feature/feature-branch' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'fourth commit'
end
end
it 'returns the checked out revision' do
options = { :hg => fixture('mercurial-repo') }
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
downloader.checkout_options.should == {
:hg => fixture('mercurial-repo'),
:revision => 'df97b9ee89577f2da1925154472888b2b57e971e',
}
end
it 'returns whether the provided options are specific' do
Downloader.for_target('path', :hg => 'url').options_specific?.should.be.false
Downloader.for_target('path', :hg => 'url', :revision => '').options_specific?.should.be.true
Downloader.for_target('path', :hg => 'url', :tag => '').options_specific?.should.be.true
Downloader.for_target('path', :hg => 'url', :branch => '').options_specific?.should.be.false
end
it 'raises if it fails to download' do
options = { :hg => 'missing-repo', :revision => '46198bb3af96' }
downloader = Downloader.for_target(tmp_folder, options)
lambda { downloader.download }.should.raise DownloaderError
end
it 'checks out a specific tag' do
options = { :hg => fixture('mercurial-repo'), :tag => '1.0.0' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
downloader.checkout_options.should == {
:hg => fixture('mercurial-repo'),
:revision => '3c8b8d211b03c7e686049a8558e4c297104291eb',
}
end
it 'checks out a specific branch head' do
options = { :hg => fixture('mercurial-repo'), :branch => 'feature/feature-branch' }
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
downloader.checkout_options.should == {
:hg => fixture('mercurial-repo'),
:revision => '61118fa8988c2b2eae826f48abd1e3340dae0c6b',
}
end
it 'has no preprocessing' do
options = { :hg => fixture('mercurial-repo'), :tag => '1.0.0' }
new_options = Downloader.preprocess_options(options)
new_options.should == options
end
end
describe ':bad input' do
it 'bails when you provide a bad input' do
options = { :hg => '--config=alias.clone=!touch ./HELLO2;' }
e = lambda { Downloader.for_target(tmp_folder, options).download }.should.raise DownloaderError
e.message.should.match /Provided unsafe input/
end
it 'bails when you provide a bad input2' do
options = { :hg => 'foo/bar', :revision => '--config=alias.clone=!touch ./HELLO3;' }
e = lambda { Downloader.for_target(tmp_folder, options).download }.should.raise DownloaderError
e.message.should.match /Provided unsafe input/
end
end
end
end