summaryrefslogtreecommitdiff
path: root/test/uri/test_ftp.rb
blob: a7b59efebf5912ad6d4bac36352ba89d26c71092 (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
require 'test/unit'
require 'uri/ftp'

module URI


class TestFTP < Test::Unit::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.scheme, url.userinfo, url.host, url.port,
      url.path, url.opaque
    ]
    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/')
    ary = u.component.collect {|c| u.send(c)}
    assert_equal(ary, u.select(*u.component))
    assert_raises(ArgumentError) do
      u.select(:scheme, :host, :not_exist, :port)
    end
  end
end


end