require 'spec_helper' require_relative '../../lib/sredder/sredderc' describe Sredder::Sredderc do def sample_file File.expand_path('spec/sample.sredderc') end describe 'initialization' do it 'sets the default file_path' do Sredder::Sredderc.new.file_path.should == File.expand_path('~/.sredderc') end end describe '#exists?' do it 'returns true if the file exists' do Sredder::Sredderc.new(sample_file).exists?.should be_true end it 'returns false if the file does not exist' do Sredder::Sredderc.new('/some/path').exists?.should be_false end end describe '#load' do it 'does not open the file if it does not exists' do File.should_receive(:open).never Sredder::Sredderc.new('/some/path').load end it 'loads the token and secret from the file if it exists' do rc = Sredder::Sredderc.new(sample_file) rc.load rc.secret.should == 'secret' rc.token.should == 'token' end end describe '#save' do it 'writes the data to the file' do io_stub = stub('io') io_stub.should_receive(:puts).with('secret') io_stub.should_receive(:puts).with('token') File.stub(:open).and_yield(io_stub) rc = Sredder::Sredderc.new(sample_file) rc.secret = 'secret' rc.token = 'token' rc.save end end end