Sha256: ac8f0869e2cbd94e84e0c1d8fc23b927becab9c00482501ed2ec9b57085b451a

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

require 'helper'
require 'active_support/secure_random'

class TestPathname < Test::Unit::TestCase
  
  context "A normal Pathname object" do
  
    should "be enquotable" do
      assert_equal '"/"', Pathname.new('/').enquote
    end
    
    should "know if its the current pwd or not (regardless of the requested directory actually existing)" do
      Dir.chdir('/tmp')
      assert Pathname.new('/tmp').current_path?
      assert !Pathname.new('/i/do/not/exist').current_path?
    end
  
  end

  context "When working with directories" do
  
    setup do
      @tmp     = Dir.mktmpdir
      @subdirs = []
      5.times { @subdirs << File.join(@tmp, ActiveSupport::SecureRandom.hex(5)) }
      @subdirs.each { |subdir| ensure_mkdir(subdir) }
      @subdirs.map! { |subdir| Pathname.new(subdir)  }
    end

    teardown do
      assert FileUtils.rm_r(@tmp)
    end
    
    context "directories" do
  
      should "return all subdirectory names as an array" do
        result = Pathname.new(@tmp).children_directories.map { |pathname| pathname }
        assert_equal @subdirs.sort, result.sort
      end
      
      should "yield all subdirectories in a block" do
        result = []
        Pathname.new(@tmp).children_directories { |dir| result << dir }
        assert_equal @subdirs.sort, Pathname.new(@tmp).children_directories.sort
      end
      
    end # context "directories"
  
  end # context "When working with directories"
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
csd-0.1.9 test/unit/test_pathname.rb
csd-0.1.8 test/unit/test_pathname.rb
csd-0.1.7 test/unit/test_pathname.rb
csd-0.1.6 test/unit/test_pathname.rb
csd-0.1.5 test/unit/test_pathname.rb
csd-0.1.4 test/unit/test_pathname.rb
csd-0.1.3 test/unit/test_pathname.rb
csd-0.1.2 test/unit/test_pathname.rb
csd-0.1.1 test/unit/test_pathname.rb
csd-0.1.0 test/unit/test_pathname.rb