Sha256: d60347ada9833446d180a04d446e5010b77f31c943bf92332a055cbe11d0568b

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe File do
  describe ".relative_path" do
    it "should return the relative path between two files" do
      File.relative_path('a/b/c/d.html', 'a/b/d/q.html').should == '../d/q.html'
    end
  
    it "should return the relative path between two directories" do
      File.relative_path('a/b/c/d/', 'a/b/d/').should == '../d'
    end
  
    it "should return only the to file if from file is in the same directory as the to file" do
      File.relative_path('a/b/c/d', 'a/b/c/e').should == 'e'
    end
  
    it "should handle non-normalized paths" do
      File.relative_path('Hello/./I/Am/Fred', 'Hello/Fred').should == '../../Fred'
      File.relative_path('A//B/C', 'Q/X').should == '../../Q/X'
    end
  end
  
  describe '.cleanpath' do
    it "should clean double brackets" do
      File.cleanpath('A//B/C').should == "A/B/C"
    end
    
    it "should clean a path with ." do
      File.cleanpath('Hello/./I/.Am/Fred').should == "Hello/I/.Am/Fred"
    end

    it "should clean a path with .." do
      File.cleanpath('Hello/../World').should == "World"
    end

    it "should clean a path with multiple .." do
      File.cleanpath('A/B/C/../../D').should == "A/D"
    end

    it "should clean a path ending in .." do
      File.cleanpath('A/B/C/D/..').should == "A/B/C"
    end
    
    it "should not pass the initial directory" do
      File.cleanpath('C/../../D').should == "../D"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yard-0.5.1 spec/core_ext/file_spec.rb
yard-0.5.0 spec/core_ext/file_spec.rb
yard-0.4.0 spec/core_ext/file_spec.rb