summaryrefslogtreecommitdiff
path: root/test/uri/test_ftp.rb
blob: 123eb22e4a5b94070c676135589b13ec02bb5e17 (plain)
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
#
# $Id$
#
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
#

require 'runit/testcase'
require 'runit/testsuite'
require 'runit/cui/testrunner'

require 'uri/ftp'
module URI
  class Generic
    def to_ary
      component_ary
    end
  end
end

class TestFTP < RUNIT::TestCase
  def setup
  end

  def test_parse
    url = URI.parse('ftp://user:pass@host.com/abc/def')
    assert_kind_of(URI::FTP, url)

    exp = [
      'ftp',
      'user:pass', 'host.com', URI::FTP.default_port, 
      '/abc/def', nil,
    ]
    ary = url.to_ary
    assert_equal(exp, ary)

    assert_equal('user', url.user)
    assert_equal('pass', url.password)
  end

  def test_select
    assert_equal(['ftp', 'a.b.c', 21], URI.parse('ftp://a.b.c/').select(:scheme, :host, :port))
    u = URI.parse('ftp://a.b.c/')
    assert_equal(u.to_ary, u.select(*u.component))
    assert_exception(ArgumentError) do
      u.select(:scheme, :host, :not_exist, :port)
    end
  end
end

if $0 == __FILE__
  if ARGV.size == 0
    suite = TestFTP.suite
  else
    suite = RUNIT::TestSuite.new
    ARGV.each do |testmethod|
      suite.add_test(TestFTP.new(testmethod))
    end
  end
  RUNIT::CUI::TestRunner.run(suite)
end