Sha256: 6c4fa71708fd281873ef20b073300f47cd454a4e873f03d1d2916b3aefd305ef

Contents?: true

Size: 1.54 KB

Versions: 18

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

describe Semi::Variables::Path do

  [
    # Test string,
    '/',
    '/bin',
    '/usr/local/bin/csh',
    '~user',
    '~/.bashrc',
    '~looser/plan.txt',
    './test',
    '../../usr/bin/foobar',
    '.././.././test-file',
    '/tmp/backup~',
    '/home/user/.git/config',
    'sub/directory/file.txt',
  ].each do |test|
    it "stores '#{test}' correctly" do
      expect(Semi::Variables::Path.new(test).value).to eq test
    end
  end
  
  # Currently the regex used to identify paths allows almost 
  # any string.
  #[
  #  'foo.txt',
  #].each do |test|
  #  it "rejects '#{test}'" do
  #    expect{Semi::Variables::Path.new(test)}.to raise_error(Semi::VariableError)
  #  end
  #end

  context "with relative paths" do
    let (:path)  {Semi::Variables::Path.new('../some/dir/file.txt')}

    it "#path returns ../some/dir/" do
      expect(path.path).to eq '../some/dir/'
    end
  
    it "#file returns file.text" do
      expect(path.file).to eq 'file.txt'
    end
  end

  context "with absolute paths" do
    let (:path)  {Semi::Variables::Path.new('/some/dir/file.txt')}

    it "#path returns /some/dir/" do
      expect(path.path).to eq '/some/dir/'
    end
  
    it "#file returns file.text" do
      expect(path.file).to eq 'file.txt'
    end
  end

  context "with partial paths" do
    let (:path)  {Semi::Variables::Path.new('some/dir/file.txt')}

    it "#path returns some/dir/" do
      expect(path.path).to eq 'some/dir/'
    end
  
    it "#file returns file.text" do
      expect(path.file).to eq 'file.txt'
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
semi-0.8.6 spec/semi_variables_path_spec.rb
semi-0.8.5 spec/semi_variables_path_spec.rb
semi-0.8.4 spec/semi_variables_path_spec.rb
semi-0.8.3 spec/semi_variables_path_spec.rb
semi-0.8.2 spec/semi_variables_path_spec.rb
semi-0.8.1 spec/semi_variables_path_spec.rb
semi-0.8.0 spec/semi_variables_path_spec.rb
semi-0.7.1 spec/semi_variables_path_spec.rb
semi-0.7.0 spec/semi_variables_path_spec.rb
semi-0.6.1 spec/semi_variables_path_spec.rb
semi-0.6.0 spec/semi_variables_path_spec.rb
semi-0.5.1 spec/semi_variables_path_spec.rb
semi-0.5.0 spec/semi_variables_path_spec.rb
semi-0.4.0 spec/semi_variables_path_spec.rb
semi-0.3.6 spec/semi_variables_path_spec.rb
semi-0.3.5 spec/semi_variables_path_spec.rb
semi-0.3.3 spec/semi_variables_path_spec.rb
semi-0.3.2 spec/semi_variables_path_spec.rb