Sha256: d3bcec5b2f896b5b4ea8354e4c91e5d038c8948b0b74defc17c956739c4f4d90

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

# encoding: utf-8
require 'core_ext/file'

describe 'File::absolute_path?' do
  context 'posix' do
    before(:each) do
      stub_const("File::ALT_SEPARATOR", nil)
      stub_const("File::ABSOLUTE_PATH_PATTERN", File::POSIX_ABSOLUTE_PATH_PATTERN)
    end
    context 'when given an absolute path' do
      %w(
        /foo/bar
        /C/Windows/system32/
      ).each do |path|
        context "(#{path})" do
          context 'the return value' do
            subject { File::absolute_path?(path) }
            it { should be_true }
          end
        end
      end
    end
    context 'when given a relative path' do
      %w(
        C:/foo/bar
        \\foo\\bar
        C:\\foo\\bar
        foo/bar
        foo
        ./foo/bar
        ../foo/bar
        C:foo/bar
      ).each do |path|
        context "(#{path})" do
          context 'the return value' do
            subject { File::absolute_path?(path) }
            it { should be_false }
          end
        end
      end
    end
  end

  context 'windows' do
    before(:each) do
      stub_const("File::ALT_SEPARATOR", '\\')
      stub_const("File::ABSOLUTE_PATH_PATTERN", File::WINDOWS_ABSOLUTE_PATH_PATTERN)
    end
    context 'when given an absolute path' do
      %w(
        /foo/bar
        C:/foo/bar
        \\foo\\bar
        C:\\foo\\bar
        /C/Windows/system32/
      ).each do |path|
        context "(#{path})" do
          context 'the return value' do
            subject { File::absolute_path?(path) }
            it { should be_true }
          end
        end
      end
    end
    context 'when given a relative path' do
      %w(
        foo/bar
        foo
        ./foo/bar
        ../foo/bar
        C:foo/bar
      ).each do |path|
        context "(#{path})" do
          context 'the return value' do
            subject { File::absolute_path?(path) }
            it { should be_false }
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/cliver-0.3.2/spec/core_ext/file_spec.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/cliver-0.3.2/spec/core_ext/file_spec.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/cliver-0.3.2/spec/core_ext/file_spec.rb
cliver-0.3.2 spec/core_ext/file_spec.rb
cliver-0.3.1 spec/core_ext/file_spec.rb
cliver-0.2.2 spec/core_ext/file_spec.rb