2 # Copyright Michael Orlitzky
4 # http://michael.orlitzky.com/
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # http://www.fsf.org/licensing/licenses/gpl.html
20 require 'whatever-dl/uri_utilities.rb'
22 class UriUtilitiesTest
< Test
::Unit::TestCase
24 def test_system_call_exception_on_connection_refused
25 uu
= UriUtilities
.new()
27 # *Hopefully* this connection is refused.
28 example_uri
= 'http://localhost:1/'
29 uri
= URI
.parse(example_uri
)
31 assert_raise Errno
::ECONNREFUSED do
32 uu
.download_with_progress_bar(uri
, 'dummy.tmp')
35 # This should be gone since there was an error.
36 assert(!File
.exists
?('dummy.tmp'))
40 def test_access_denied_on_unwritable_outfile
41 # Get rid of the dummy file if it already exists.
42 File
.delete('dummy.tmp') if File
.exists
?('dummy.tmp')
44 File
.new('dummy.tmp', 'w')
46 # Make the new file unwritable
47 File
.chmod(0400, 'dummy.tmp')
49 uu
= UriUtilities
.new()
51 # *Hopefully* this connection is refused.
52 example_uri
= 'http://localhost:1/'
53 uri
= URI
.parse(example_uri
)
55 assert_raise Errno
::EACCES do
56 uu
.download_with_progress_bar(uri
, 'dummy.tmp')
59 # This should *not* be deleted, since it was unwritable,
60 # and we got an IO error instead of an HTTP or connection
62 assert(File
.exists
?('dummy.tmp'))
64 # Ok, now we delete it anyway since it will mess up the other tests.
65 File
.delete('dummy.tmp')