spec/tty/terminal/home_spec.rb in tty-0.0.11 vs spec/tty/terminal/home_spec.rb in tty-0.1.0

- old
+ new

@@ -1,37 +1,35 @@ -# -*- encoding: utf-8 -*- +# encoding: utf-8 require 'spec_helper' describe TTY::Terminal, '#home' do + subject(:terminal) { described_class.new } - before { ENV.stub(:[]) } + before { allow(ENV).to receive(:[]) } - 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') + allow(File).to receive(:expand_path).and_return('/home/user') + expect(terminal.home).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') + allow(ENV).to receive(:[]).with('HOME').and_return('/home/user') + expect(terminal.home).to eq('/home/user') end context 'when failed to expand' do - before { File.should_receive(:expand_path).and_raise(RuntimeError) } + before { allow(File).to receive(:expand_path).and_raise(RuntimeError) } it 'returns C:/ on windows' do - TTY::System.stub(:windows?).and_return true - expect(terminal).to eql("C:/") + allow(TTY::System).to receive(:windows?).and_return(true) + expect(terminal.home).to eql("C:/") end it 'returns root on unix' do - TTY::System.stub(:windows?).and_return false - expect(terminal).to eql("/") + allow(TTY::System).to receive(:windows?).and_return(false) + expect(terminal.home).to eql("/") end end - end