Class CoreEx::PathnameExTest
In: lib/core_ex/pathname.rb
Parent: Test::Unit::TestCase

Methods

Included Modules

YamlExtension::Assertions CoreEx::Pathname::Assertions Pathname::ShortCut

Public Instance methods

[Source]

# File lib/core_ex/pathname.rb, line 235
      def setup
       @test = __FILE__.to_path.dirname.parent.parent + 'test'
       @fixtures  = @test + 'fixtures'
       @req  = @fixtures + 'require'
       @s = 'test_require'
       @s_dne = 'test_require_dne'
       @s_so = 'test_require_so.so'
       @s_rb = 'test_require_rb.rb'
       @p = @s.to_path
       @p_dne = @s_dne.to_path
       @p_so = @s_so.to_path
       @p_rb = @s_rb.to_path
       @ls = [ @s, @s_dne, @s_so, @s_rb ]
       @lp = [ @p, @p_dne, @p_rb ] # FIXME @p_so on mac
       @l = @ls + @lp
       @load_path = $LOAD_PATH
      end

[Source]

# File lib/core_ex/pathname.rb, line 288
      def test_1_expand_path_with
        @lp.each { |x| assert_expand_path_with(x, nil) }
      end

[Source]

# File lib/core_ex/pathname.rb, line 292
      def test_2_expand_path_with
        @load_path << @req
        @lp.delete(@p_dne)
        @lp.each { |x| assert_expand_path_with(x, @req + x) }
        @lp.each { |x| assert_expand_path_with(@req + x, @req + x) }
        assert_expand_path_with(@p_dne, nil)
      end

Tests

[Source]

# File lib/core_ex/pathname.rb, line 256
      def test_ensure_dir
        p = nil
        begin
          name = Tempfile.new('pathname')
          p = name.path.to_path
          name.delete
          assert(! p.directory?, 'no directory')
          assert_nothing_raised { p.ensure_mkdir }
          assert(p.directory?, 'directory')
          assert_nothing_raised { p.ensure_mkdir }
          assert(p.directory?, 'still directory')
        ensure
          p.rmdir unless p.nil?
        end
      end

[Source]

# File lib/core_ex/pathname.rb, line 274
      def test_simple
        assert_equal([`path.ext1`, '.ext2'], `path.ext1.ext2`.extsplit)
        assert_equal([`path`, ''], `path`.extsplit)
        assert_equal([`path`, '.'], `path.`.extsplit)
        assert_equal([`path`, '-ext'], `path-ext`.extsplit('-'))
        assert_equal([`path-ext1`, '-ext2'], `path-ext1-ext2`.extsplit('-'))
      end

[Source]

# File lib/core_ex/pathname.rb, line 282
      def test_slash
        assert_equal(`path/to/a/file`, `path`/'to'/'a'/'file')
        path, to, a, file = `/path`, 'to', 'a', 'file'
        assert_equal(`/path/to/a/file`, path/to/a/file)
      end

[Source]

# File lib/core_ex/pathname.rb, line 300
      def test_yaml
        str = 'foo/bar/baz.rb'
        assert_yaml_load "!path #{str}", ::Pathname, str.to_path
        assert_equal('baz.rb', @val.basename.to_s)
        assert_equal(str, @val.to_s)
        assert_yaml_dump str.to_path, @ref
      end

[Validate]