Sha256: 85fea86d5df3f7304e53c50f402993786d9d050109b58cb1da8e27beff5e61b1

Contents?: true

Size: 916 Bytes

Versions: 4

Compression:

Stored size: 916 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Terminal, '#home' do

  before { ENV.stub!(:[]) }

  subject(:terminal) { described_class.new.home }

  after { terminal.instance_variable_set(:@home, nil) }

  it 'expands user home path if HOME environemnt not set' do
    File.stub!(:expand_path).and_return('/home/user')
    expect(terminal).to eql('/home/user')
  end

  it 'defaults to user HOME environment' do
    ENV.stub!(:[]).with('HOME').and_return('/home/user')
    expect(terminal).to eq('/home/user')
  end

  context 'when failed to expand' do
    before { File.should_receive(:expand_path).and_raise(RuntimeError) }

    it 'returns C:/ on windows' do
      TTY::System.stub(:windows?).and_return true
      expect(terminal).to eql("C:/")
    end

    it 'returns root on unix' do
      TTY::System.stub(:windows?).and_return false
      expect(terminal).to eql("/")
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tty-0.0.9 spec/tty/terminal/home_spec.rb
tty-0.0.8 spec/tty/terminal/home_spec.rb
tty-0.0.7 spec/tty/terminal/home_spec.rb
tty-0.0.6 spec/tty/terminal/home_spec.rb