ittayd-buildr 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +62 -9
- data/NOTICE +1 -1
- data/README.rdoc +9 -21
- data/Rakefile +20 -39
- data/_buildr +1 -0
- data/{spec/java/ant.rb → _jbuildr} +11 -15
- metadata +30 -210
- data/DISCLAIMER +0 -7
- data/addon/buildr/antlr.rb +0 -65
- data/addon/buildr/cobertura.rb +0 -22
- data/addon/buildr/drb.rb +0 -281
- data/addon/buildr/emma.rb +0 -22
- data/addon/buildr/hibernate.rb +0 -142
- data/addon/buildr/javacc.rb +0 -85
- data/addon/buildr/jdepend.rb +0 -60
- data/addon/buildr/jetty.rb +0 -248
- data/addon/buildr/jibx.rb +0 -86
- data/addon/buildr/nailgun.rb +0 -221
- data/addon/buildr/openjpa.rb +0 -90
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +0 -41
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +0 -144
- data/addon/buildr/path.rb +0 -136
- data/addon/buildr/xmlbeans.rb +0 -93
- data/buildr.buildfile +0 -53
- data/buildr.gemspec +0 -58
- data/doc/css/default.css +0 -228
- data/doc/css/print.css +0 -100
- data/doc/css/syntax.css +0 -52
- data/doc/images/apache-incubator-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/pages/artifacts.textile +0 -207
- data/doc/pages/building.textile +0 -240
- data/doc/pages/contributing.textile +0 -208
- data/doc/pages/download.textile +0 -62
- data/doc/pages/extending.textile +0 -175
- data/doc/pages/getting_started.textile +0 -273
- data/doc/pages/index.textile +0 -42
- data/doc/pages/languages.textile +0 -407
- data/doc/pages/mailing_lists.textile +0 -17
- data/doc/pages/more_stuff.textile +0 -314
- data/doc/pages/packaging.textile +0 -427
- data/doc/pages/projects.textile +0 -274
- data/doc/pages/recipes.textile +0 -103
- data/doc/pages/settings_profiles.textile +0 -274
- data/doc/pages/testing.textile +0 -212
- data/doc/pages/troubleshooting.textile +0 -103
- data/doc/pages/whats_new.textile +0 -323
- data/doc/print.haml +0 -51
- data/doc/print.toc.yaml +0 -29
- data/doc/scripts/buildr-git.rb +0 -412
- data/doc/scripts/install-jruby.sh +0 -44
- data/doc/scripts/install-linux.sh +0 -64
- data/doc/scripts/install-osx.sh +0 -52
- data/doc/site.haml +0 -56
- data/doc/site.toc.yaml +0 -47
- data/etc/KEYS +0 -151
- data/etc/git-svn-authors +0 -16
- data/lib/buildr.rb +0 -33
- data/lib/buildr/core.rb +0 -29
- data/lib/buildr/core/application.rb +0 -665
- data/lib/buildr/core/build.rb +0 -311
- data/lib/buildr/core/checks.rb +0 -254
- data/lib/buildr/core/common.rb +0 -150
- data/lib/buildr/core/compile.rb +0 -590
- data/lib/buildr/core/environment.rb +0 -117
- data/lib/buildr/core/filter.rb +0 -366
- data/lib/buildr/core/generate.rb +0 -195
- data/lib/buildr/core/help.rb +0 -119
- data/lib/buildr/core/osx.rb +0 -49
- data/lib/buildr/core/progressbar.rb +0 -156
- data/lib/buildr/core/project.rb +0 -923
- data/lib/buildr/core/test.rb +0 -715
- data/lib/buildr/core/transports.rb +0 -560
- data/lib/buildr/core/util.rb +0 -294
- data/lib/buildr/groovy.rb +0 -18
- data/lib/buildr/groovy/bdd.rb +0 -106
- data/lib/buildr/groovy/compiler.rb +0 -138
- data/lib/buildr/ide.rb +0 -19
- data/lib/buildr/ide/eclipse.rb +0 -222
- data/lib/buildr/ide/idea.ipr.template +0 -300
- data/lib/buildr/ide/idea.rb +0 -190
- data/lib/buildr/ide/idea7x.ipr.template +0 -290
- data/lib/buildr/ide/idea7x.rb +0 -212
- data/lib/buildr/java.rb +0 -23
- data/lib/buildr/java/ant.rb +0 -92
- data/lib/buildr/java/bdd.rb +0 -451
- data/lib/buildr/java/cobertura.rb +0 -236
- data/lib/buildr/java/commands.rb +0 -211
- data/lib/buildr/java/compiler.rb +0 -348
- data/lib/buildr/java/deprecated.rb +0 -141
- data/lib/buildr/java/emma.rb +0 -238
- data/lib/buildr/java/jruby.rb +0 -117
- data/lib/buildr/java/jtestr_runner.rb.erb +0 -116
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +0 -119
- data/lib/buildr/java/packaging.rb +0 -717
- data/lib/buildr/java/pom.rb +0 -174
- data/lib/buildr/java/rjb.rb +0 -155
- data/lib/buildr/java/test_result.rb +0 -307
- data/lib/buildr/java/tests.rb +0 -329
- data/lib/buildr/java/version_requirement.rb +0 -172
- data/lib/buildr/packaging.rb +0 -24
- data/lib/buildr/packaging/archive.rb +0 -488
- data/lib/buildr/packaging/artifact.rb +0 -759
- data/lib/buildr/packaging/artifact_namespace.rb +0 -972
- data/lib/buildr/packaging/artifact_search.rb +0 -140
- data/lib/buildr/packaging/gems.rb +0 -102
- data/lib/buildr/packaging/package.rb +0 -233
- data/lib/buildr/packaging/tar.rb +0 -186
- data/lib/buildr/packaging/version_requirement.rb +0 -172
- data/lib/buildr/packaging/zip.rb +0 -64
- data/lib/buildr/packaging/ziptask.rb +0 -313
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/scala.rb +0 -19
- data/lib/buildr/scala/compiler.rb +0 -109
- data/lib/buildr/scala/tests.rb +0 -203
- data/rakelib/apache.rake +0 -191
- data/rakelib/changelog.rake +0 -57
- data/rakelib/doc.rake +0 -103
- data/rakelib/package.rake +0 -76
- data/rakelib/release.rake +0 -65
- data/rakelib/rspec.rake +0 -83
- data/rakelib/rubyforge.rake +0 -56
- data/rakelib/scm.rake +0 -49
- data/rakelib/setup.rake +0 -81
- data/rakelib/stage.rake +0 -48
- data/spec/addon/drb_spec.rb +0 -328
- data/spec/core/application_spec.rb +0 -419
- data/spec/core/build_spec.rb +0 -423
- data/spec/core/checks_spec.rb +0 -519
- data/spec/core/common_spec.rb +0 -670
- data/spec/core/compile_spec.rb +0 -582
- data/spec/core/generate_spec.rb +0 -33
- data/spec/core/project_spec.rb +0 -776
- data/spec/core/test_spec.rb +0 -1098
- data/spec/core/transport_spec.rb +0 -500
- data/spec/groovy/bdd_spec.rb +0 -80
- data/spec/groovy/compiler_spec.rb +0 -239
- data/spec/ide/eclipse_spec.rb +0 -311
- data/spec/java/bdd_spec.rb +0 -358
- data/spec/java/cobertura_spec.rb +0 -77
- data/spec/java/compiler_spec.rb +0 -446
- data/spec/java/emma_spec.rb +0 -120
- data/spec/java/java_spec.rb +0 -96
- data/spec/java/packaging_spec.rb +0 -1120
- data/spec/java/test_coverage_spec.rb +0 -255
- data/spec/java/tests_spec.rb +0 -471
- data/spec/packaging/archive_spec.rb +0 -503
- data/spec/packaging/artifact_namespace_spec.rb +0 -646
- data/spec/packaging/artifact_spec.rb +0 -795
- data/spec/packaging/packaging_helper.rb +0 -63
- data/spec/packaging/packaging_spec.rb +0 -589
- data/spec/sandbox.rb +0 -139
- data/spec/scala/compiler_spec.rb +0 -228
- data/spec/scala/tests_spec.rb +0 -215
- data/spec/spec_helpers.rb +0 -327
- data/spec/version_requirement_spec.rb +0 -123
data/spec/core/transport_spec.rb
DELETED
@@ -1,500 +0,0 @@
|
|
1
|
-
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
-
# contributor license agreements. See the NOTICE file distributed with this
|
3
|
-
# work for additional information regarding copyright ownership. The ASF
|
4
|
-
# licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
-
# "License"); you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
-
# License for the specific language governing permissions and limitations under
|
14
|
-
# the License.
|
15
|
-
|
16
|
-
|
17
|
-
require File.join(File.dirname(__FILE__), '../spec_helpers')
|
18
|
-
|
19
|
-
|
20
|
-
describe URI, '#download' do
|
21
|
-
before do
|
22
|
-
write @source = 'source', @content = 'Just a file'
|
23
|
-
@uri = URI("file://#{File.expand_path(@source)}")
|
24
|
-
@target = 'target'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should download file if found' do
|
28
|
-
@uri.download @target
|
29
|
-
file(@target).should contain(@content)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should fail if file not found' do
|
33
|
-
lambda { (@uri + 'missing').download @target }.should raise_error(URI::NotFoundError)
|
34
|
-
file(@target).should_not exist
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should work the same way from static method with URI' do
|
38
|
-
URI.download @uri, @target
|
39
|
-
file(@target).should contain(@content)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should work the same way from static method with String' do
|
43
|
-
URI.download @uri.to_s, @target
|
44
|
-
file(@target).should contain(@content)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should download to a task' do
|
48
|
-
@uri.download file(@target)
|
49
|
-
file(@target).should contain(@content)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should download to a file' do
|
53
|
-
File.open(@target, 'w') { |file| @uri.download file }
|
54
|
-
file(@target).should contain(@content)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
describe URI, '#upload' do
|
60
|
-
before do
|
61
|
-
write @source = 'source', @content = 'Just a file'
|
62
|
-
@target = 'target'
|
63
|
-
@uri = URI("file://#{File.expand_path(@target)}")
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should upload file if found' do
|
67
|
-
@uri.upload @source
|
68
|
-
file(@target).should contain(@content)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should fail if file not found' do
|
72
|
-
lambda { @uri.upload @source.ext('missing') }.should raise_error(URI::NotFoundError)
|
73
|
-
file(@target).should_not exist
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should work the same way from static method with URI' do
|
77
|
-
URI.upload @uri, @source
|
78
|
-
file(@target).should contain(@content)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should work the same way from static method with String' do
|
82
|
-
URI.upload @uri.to_s, @source
|
83
|
-
file(@target).should contain(@content)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should upload from a task' do
|
87
|
-
@uri.upload file(@source)
|
88
|
-
file(@target).should contain(@content)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should create MD5 hash' do
|
92
|
-
@uri.upload file(@source)
|
93
|
-
file(@target.ext('.md5')).should contain(Digest::MD5.hexdigest(@content))
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should create SHA1 hash' do
|
97
|
-
@uri.upload file(@source)
|
98
|
-
file(@target.ext('.sha1')).should contain(Digest::SHA1.hexdigest(@content))
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should upload an entire directory' do
|
102
|
-
mkpath 'dir' ; write 'dir/test', 'in directory'
|
103
|
-
mkpath 'dir/nested' ; write 'dir/nested/test', 'in nested directory'
|
104
|
-
@uri.upload 'dir'
|
105
|
-
file(@target).should contain('test', 'nested/test')
|
106
|
-
file(@target + '/test').should contain('in directory')
|
107
|
-
file(@target + '/nested/test').should contain('in nested directory')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
describe URI::FILE do
|
113
|
-
it 'should complain about file:' do
|
114
|
-
lambda { URI('file:') }.should raise_error(URI::InvalidURIError)
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'should accept file:something as file:///something' do
|
118
|
-
URI('file:something').should eql(URI('file:///something'))
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'should accept file:/ as file:///' do
|
122
|
-
URI('file:/').should eql(URI('file:///'))
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should accept file:/something as file:///something' do
|
126
|
-
URI('file:/something').should eql(URI('file:///something'))
|
127
|
-
end
|
128
|
-
|
129
|
-
it 'should complain about file://' do
|
130
|
-
lambda { URI('file://').should eql(URI('file:///')) }.should raise_error(URI::InvalidURIError)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'should accept file://something as file://something/' do
|
134
|
-
URI('file://something').should eql(URI('file://something/'))
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'should accept file:///something' do
|
138
|
-
URI('file:///something').should be_kind_of(URI::FILE)
|
139
|
-
URI('file:///something').to_s.should eql('file:///something')
|
140
|
-
URI('file:///something').path.should eql('/something')
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should treat host as path when host name is a Windows drive' do
|
144
|
-
URI('file://c:/something').should eql(URI('file:///c:/something'))
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
describe URI::FILE, '#read' do
|
150
|
-
before do
|
151
|
-
@filename = 'readme'
|
152
|
-
@uri = URI("file:///#{File.expand_path(@filename)}")
|
153
|
-
@content = 'Readme. Please!'
|
154
|
-
write 'readme', @content
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should not complain about excessive options' do
|
158
|
-
@uri.read :proxy=>[], :lovely=>true
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'should read the file' do
|
162
|
-
@uri.read.should eql(@content)
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'should read the file and yield to block' do
|
166
|
-
@uri.read { |content| content.should eql(@content) }
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'should raise NotFoundError if file doesn\'t exist' do
|
170
|
-
lambda { (@uri + 'notme').read }.should raise_error(URI::NotFoundError)
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'should raise NotFoundError if file is actually a directory' do
|
174
|
-
mkpath 'dir'
|
175
|
-
lambda { (@uri + 'dir').read }.should raise_error(URI::NotFoundError)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
|
180
|
-
describe URI::FILE, '#write' do
|
181
|
-
before do
|
182
|
-
@filename = 'readme'
|
183
|
-
@uri = URI("file:///#{File.expand_path(@filename)}")
|
184
|
-
@content = 'Readme. Please!'
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'should not complain about excessive options' do
|
188
|
-
@uri.write @content, :proxy=>[], :lovely=>true
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'should write the file from a string' do
|
192
|
-
@uri.write @content
|
193
|
-
read(@filename).should eql(@content)
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'should write the file from a reader' do
|
197
|
-
reader = Object.new
|
198
|
-
class << reader
|
199
|
-
def read(bytes) ; @array.pop ; end
|
200
|
-
end
|
201
|
-
reader.instance_variable_set :@array, [@content]
|
202
|
-
@uri.write reader
|
203
|
-
read(@filename).should eql(@content)
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'should write the file from a block' do
|
207
|
-
array = [@content]
|
208
|
-
@uri.write { array.pop }
|
209
|
-
read(@filename).should eql(@content)
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'should not create file if read fails' do
|
213
|
-
@uri.write { fail } rescue nil
|
214
|
-
file(@filename).should_not exist
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
|
219
|
-
describe URI::HTTP, '#read' do
|
220
|
-
before do
|
221
|
-
@proxy = 'http://john:smith@myproxy:8080'
|
222
|
-
@domain = 'domain'
|
223
|
-
@host_domain = "host.#{@domain}"
|
224
|
-
@path = "/foo/bar/baz"
|
225
|
-
@query = "?query"
|
226
|
-
@uri = URI("http://#{@host_domain}#{@path}#{@query}")
|
227
|
-
@no_proxy_args = [@host_domain, 80]
|
228
|
-
@proxy_args = @no_proxy_args + ['myproxy', 8080, 'john', 'smith']
|
229
|
-
@http = mock('http')
|
230
|
-
@http.stub!(:request).and_yield(Net::HTTPNotModified.new(nil, nil, nil))
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'should not use proxy unless proxy is set' do
|
234
|
-
Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
|
235
|
-
@uri.read
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'should use proxy from environment variable HTTP_PROXY' do
|
239
|
-
ENV['HTTP_PROXY'] = @proxy
|
240
|
-
Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
|
241
|
-
@uri.read
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'should not use proxy for hosts from environment variable NO_PROXY' do
|
245
|
-
ENV['HTTP_PROXY'] = @proxy
|
246
|
-
ENV['NO_PROXY'] = @host_domain
|
247
|
-
Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
|
248
|
-
@uri.read
|
249
|
-
end
|
250
|
-
|
251
|
-
it 'should use proxy for hosts other than those specified by NO_PROXY' do
|
252
|
-
ENV['HTTP_PROXY'] = @proxy
|
253
|
-
ENV['NO_PROXY'] = 'whatever'
|
254
|
-
Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
|
255
|
-
@uri.read
|
256
|
-
end
|
257
|
-
|
258
|
-
it 'should support comma separated list in environment variable NO_PROXY' do
|
259
|
-
ENV['HTTP_PROXY'] = @proxy
|
260
|
-
ENV['NO_PROXY'] = 'optimus,prime'
|
261
|
-
Net::HTTP.should_receive(:new).with('optimus', 80).and_return(@http)
|
262
|
-
URI('http://optimus').read
|
263
|
-
Net::HTTP.should_receive(:new).with('prime', 80).and_return(@http)
|
264
|
-
URI('http://prime').read
|
265
|
-
Net::HTTP.should_receive(:new).with('bumblebee', *@proxy_args[1..-1]).and_return(@http)
|
266
|
-
URI('http://bumblebee').read
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'should support glob pattern in NO_PROXY' do
|
270
|
-
ENV['HTTP_PROXY'] = @proxy
|
271
|
-
ENV['NO_PROXY'] = "*.#{@domain}"
|
272
|
-
Net::HTTP.should_receive(:new).once.with(*@no_proxy_args).and_return(@http)
|
273
|
-
@uri.read
|
274
|
-
end
|
275
|
-
|
276
|
-
it 'should support specific port in NO_PROXY' do
|
277
|
-
ENV['HTTP_PROXY'] = @proxy
|
278
|
-
ENV['NO_PROXY'] = "#{@host_domain}:80"
|
279
|
-
Net::HTTP.should_receive(:new).with(*@no_proxy_args).and_return(@http)
|
280
|
-
@uri.read
|
281
|
-
ENV['NO_PROXY'] = "#{@host_domain}:800"
|
282
|
-
Net::HTTP.should_receive(:new).with(*@proxy_args).and_return(@http)
|
283
|
-
@uri.read
|
284
|
-
end
|
285
|
-
|
286
|
-
it 'should not die if content size is zero' do
|
287
|
-
ok = Net::HTTPOK.new(nil, nil, nil)
|
288
|
-
ok.stub!(:read_body)
|
289
|
-
@http.stub!(:request).and_yield(ok)
|
290
|
-
Net::HTTP.should_receive(:new).and_return(@http)
|
291
|
-
$stdout.should_receive(:isatty).and_return(false)
|
292
|
-
@uri.read :progress=>true
|
293
|
-
end
|
294
|
-
|
295
|
-
it 'should use HTTP Basic authentication' do
|
296
|
-
Net::HTTP.should_receive(:new).and_return(@http)
|
297
|
-
request = mock('request')
|
298
|
-
Net::HTTP::Get.should_receive(:new).and_return(request)
|
299
|
-
request.should_receive(:basic_auth).with('john', 'secret')
|
300
|
-
URI("http://john:secret@#{@host_domain}").read
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'should include the query part when performing HTTP GET' do
|
304
|
-
# should this test be generalized or shared with any other URI subtypes?
|
305
|
-
Net::HTTP.stub!(:new).and_return(@http)
|
306
|
-
Net::HTTP::Get.should_receive(:new).with(/#{Regexp.escape(@query)}$/, nil)
|
307
|
-
@uri.read
|
308
|
-
end
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
|
313
|
-
describe URI::HTTP, '#write' do
|
314
|
-
before do
|
315
|
-
@content = 'Readme. Please!'
|
316
|
-
@uri = URI('http://john:secret@host.domain/foo/bar/baz.jar')
|
317
|
-
@http = mock('Net::HTTP')
|
318
|
-
@http.stub!(:request).and_return(Net::HTTPOK.new(nil, nil, nil))
|
319
|
-
Net::HTTP.stub!(:new).and_return(@http)
|
320
|
-
end
|
321
|
-
|
322
|
-
it 'should open connection to HTTP server' do
|
323
|
-
Net::HTTP.should_receive(:new).with('host.domain', 80).and_return(@http)
|
324
|
-
@uri.write @content
|
325
|
-
end
|
326
|
-
|
327
|
-
it 'should use HTTP basic authentication' do
|
328
|
-
@http.should_receive(:request) do |request|
|
329
|
-
request['authorization'].should == ('Basic ' + ['john:secret'].pack('m').delete("\r\n"))
|
330
|
-
Net::HTTPOK.new(nil, nil, nil)
|
331
|
-
end
|
332
|
-
@uri.write @content
|
333
|
-
end
|
334
|
-
|
335
|
-
it 'should use HTTPS if applicable' do
|
336
|
-
Net::HTTP.should_receive(:new).with('host.domain', 443).and_return(@http)
|
337
|
-
@http.should_receive(:use_ssl=).with(true)
|
338
|
-
URI(@uri.to_s.sub(/http/, 'https')).write @content
|
339
|
-
end
|
340
|
-
|
341
|
-
it 'should upload file with PUT request' do
|
342
|
-
@http.should_receive(:request) do |request|
|
343
|
-
request.should be_kind_of(Net::HTTP::Put)
|
344
|
-
Net::HTTPOK.new(nil, nil, nil)
|
345
|
-
end
|
346
|
-
@uri.write @content
|
347
|
-
end
|
348
|
-
|
349
|
-
it 'should set Content-Length header' do
|
350
|
-
@http.should_receive(:request) do |request|
|
351
|
-
request.content_length.should == @content.size
|
352
|
-
Net::HTTPOK.new(nil, nil, nil)
|
353
|
-
end
|
354
|
-
@uri.write @content
|
355
|
-
end
|
356
|
-
|
357
|
-
it 'should set Content-MD5 header' do
|
358
|
-
@http.should_receive(:request) do |request|
|
359
|
-
request['Content-MD5'].should == Digest::MD5.hexdigest(@content)
|
360
|
-
Net::HTTPOK.new(nil, nil, nil)
|
361
|
-
end
|
362
|
-
@uri.write @content
|
363
|
-
end
|
364
|
-
|
365
|
-
it 'should send entire content' do
|
366
|
-
@http.should_receive(:request) do |request|
|
367
|
-
body_stream = request.body_stream
|
368
|
-
body_stream.read(1024).should == @content
|
369
|
-
body_stream.read(1024).should be_nil
|
370
|
-
Net::HTTPOK.new(nil, nil, nil)
|
371
|
-
end
|
372
|
-
@uri.write @content
|
373
|
-
end
|
374
|
-
|
375
|
-
it 'should fail on 4xx response' do
|
376
|
-
@http.should_receive(:request).and_return(Net::HTTPBadRequest.new(nil, nil, nil))
|
377
|
-
lambda { @uri.write @content }.should raise_error(RuntimeError, /failed to upload/i)
|
378
|
-
end
|
379
|
-
|
380
|
-
it 'should fail on 5xx response' do
|
381
|
-
@http.should_receive(:request).and_return(Net::HTTPServiceUnavailable.new(nil, nil, nil))
|
382
|
-
lambda { @uri.write @content }.should raise_error(RuntimeError, /failed to upload/i)
|
383
|
-
end
|
384
|
-
|
385
|
-
end
|
386
|
-
|
387
|
-
|
388
|
-
describe URI::SFTP, '#read' do
|
389
|
-
before do
|
390
|
-
@uri = URI('sftp://john:secret@localhost/root/path/readme')
|
391
|
-
@content = 'Readme. Please!'
|
392
|
-
|
393
|
-
@ssh_session = mock('Net::SSH::Session')
|
394
|
-
@sftp_session = mock('Net::SFTP::Session')
|
395
|
-
@file_factory = mock('Net::SFTP::Operations::FileFactory')
|
396
|
-
Net::SSH.stub!(:start).with('localhost', 'john', :password=>'secret', :port=>22).and_return(@ssh_session) do
|
397
|
-
Net::SFTP::Session.should_receive(:new).with(@ssh_session).and_yield(@sftp_session).and_return(@sftp_session)
|
398
|
-
@sftp_session.should_receive(:connect!).and_return(@sftp_session)
|
399
|
-
@sftp_session.should_receive(:loop)
|
400
|
-
@sftp_session.should_receive(:file).with.and_return(@file_factory)
|
401
|
-
@file_factory.stub!(:open)
|
402
|
-
@ssh_session.should_receive(:close)
|
403
|
-
@ssh_session
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
it 'should open connection to SFTP server' do
|
408
|
-
@uri.read
|
409
|
-
end
|
410
|
-
|
411
|
-
it 'should open file for reading' do
|
412
|
-
@file_factory.should_receive(:open).with('/root/path/readme', 'r')
|
413
|
-
@uri.read
|
414
|
-
end
|
415
|
-
|
416
|
-
it 'should read contents of file and return it' do
|
417
|
-
file = mock('Net::SFTP::Operations::File')
|
418
|
-
file.should_receive(:read).with(an_instance_of(Numeric)).once.and_return(@content, nil)
|
419
|
-
@file_factory.should_receive(:open).with('/root/path/readme', 'r').and_yield(file)
|
420
|
-
@uri.read.should eql(@content)
|
421
|
-
end
|
422
|
-
|
423
|
-
it 'should read contents of file and pass it to block' do
|
424
|
-
file = mock('Net::SFTP::Operations::File')
|
425
|
-
file.should_receive(:read).with(an_instance_of(Numeric)).once.and_return(@content, nil)
|
426
|
-
@file_factory.should_receive(:open).with('/root/path/readme', 'r').and_yield(file)
|
427
|
-
content = ''
|
428
|
-
@uri.read do |chunk|
|
429
|
-
content << chunk
|
430
|
-
end
|
431
|
-
content.should eql(@content)
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
|
436
|
-
describe URI::SFTP, '#write' do
|
437
|
-
before do
|
438
|
-
@uri = URI('sftp://john:secret@localhost/root/path/readme')
|
439
|
-
@content = 'Readme. Please!'
|
440
|
-
|
441
|
-
@ssh_session = mock('Net::SSH::Session')
|
442
|
-
@sftp_session = mock('Net::SFTP::Session')
|
443
|
-
@file_factory = mock('Net::SFTP::Operations::FileFactory')
|
444
|
-
Net::SSH.stub!(:start).with('localhost', 'john', :password=>'secret', :port=>22).and_return(@ssh_session) do
|
445
|
-
Net::SFTP::Session.should_receive(:new).with(@ssh_session).and_yield(@sftp_session).and_return(@sftp_session)
|
446
|
-
@sftp_session.should_receive(:connect!).and_return(@sftp_session)
|
447
|
-
@sftp_session.should_receive(:loop)
|
448
|
-
@sftp_session.stub!(:opendir!).and_return { fail }
|
449
|
-
@sftp_session.stub!(:close)
|
450
|
-
@sftp_session.stub!(:mkdir!)
|
451
|
-
@sftp_session.should_receive(:file).with.and_return(@file_factory)
|
452
|
-
@file_factory.stub!(:open)
|
453
|
-
@ssh_session.should_receive(:close)
|
454
|
-
@ssh_session
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
it 'should open connection to SFTP server' do
|
459
|
-
@uri.write @content
|
460
|
-
end
|
461
|
-
|
462
|
-
it 'should check that path exists on server' do
|
463
|
-
paths = ['/root', '/root/path']
|
464
|
-
@sftp_session.should_receive(:opendir!).with(anything()).twice { |path| paths.shift.should == path }
|
465
|
-
@uri.write @content
|
466
|
-
end
|
467
|
-
|
468
|
-
it 'should close all opened directories' do
|
469
|
-
@sftp_session.should_receive(:opendir!).with(anything()).twice do |path|
|
470
|
-
@sftp_session.should_receive(:close).with(handle = Object.new)
|
471
|
-
handle
|
472
|
-
end
|
473
|
-
@uri.write @content
|
474
|
-
end
|
475
|
-
|
476
|
-
it 'should create missing paths on server' do
|
477
|
-
@sftp_session.should_receive(:opendir!).twice { |path| fail unless path == '/root' }
|
478
|
-
@sftp_session.should_receive(:mkdir!).once.with('/root/path', {})
|
479
|
-
@uri.write @content
|
480
|
-
end
|
481
|
-
|
482
|
-
it 'should create missing directories recursively' do
|
483
|
-
paths = ['/root', '/root/path']
|
484
|
-
@sftp_session.should_receive(:mkdir!).with(anything(), {}).twice { |path, options| paths.shift.should == path }
|
485
|
-
@uri.write @content
|
486
|
-
end
|
487
|
-
|
488
|
-
it 'should open file for writing' do
|
489
|
-
@file_factory.should_receive(:open).with('/root/path/readme', 'w')
|
490
|
-
@uri.write @content
|
491
|
-
end
|
492
|
-
|
493
|
-
it 'should write contents to file' do
|
494
|
-
file = mock('Net::SFTP::Operations::File')
|
495
|
-
file.should_receive(:write).with(@content)
|
496
|
-
@file_factory.should_receive(:open).with('/root/path/readme', 'w').and_yield(file)
|
497
|
-
@uri.write @content
|
498
|
-
end
|
499
|
-
|
500
|
-
end
|