File: test_parent.rb

package info (click to toggle)
ruby-pathname2 1.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 336 kB
  • sloc: ruby: 2,037; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (4)
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
########################################################################
# test_parent.rb
#
# Test suite for the Pathname#parent method.
########################################################################
require 'test-unit'
require 'pathname2'

class TC_Pathname_Parent < Test::Unit::TestCase
  def setup
    @path = Pathname.new("C:\\foo\\bar\\baz")
  end

  test "parent basic functionality" do
    assert_respond_to(@path, :parent)
    assert_nothing_raised{ @path.parent }
    assert_kind_of(Pathname, @path.parent)
  end

  test "parent returns expected results for an absolute path" do
    assert_equal("C:\\foo\\bar", Pathname.new("C:\\foo\\bar\\baz").parent)
    assert_equal("C:\\", Pathname.new("C:\\foo").parent)
  end

  test "parent returns expected results for a relative path" do
    assert_equal("foo", Pathname.new("foo\\bar").parent)
  end

  test "parent method returns root if already a root path" do
    assert_equal("C:\\", Pathname.new("C:\\").parent)
    assert_equal("\\\\foo\\bar", Pathname.new("//foo/bar").parent)
  end

  def teardown
    @path = nil
  end
end