# encoding: utf-8 require 'spec_helper' describe LocalStorage do let(:valid_pac_file) do <<-EOS.strip_heredoc function FindProxyForURL(url, host) { return "DIRECT" } EOS end context '#initialize' do it 'initializes storage' do file = double('File') allow(file).to receive(:name).and_return(:file1) repo = double('GitRepository') expect(repo).to receive(:[]).and_return(file) storage = LocalStorage.new(repo) file = storage.find('file1') expect(file.name).to eq(:file1) end context '#find' do it 'returns file if exists' do file = double('GitFile') allow(file).to receive(:name).and_return(:file1) repo = double('GitRepository') expect(repo).to receive(:[]).and_return(file) storage = LocalStorage.new(repo) file = storage.find('file1') expect(file.name).to eq(:file1) end it 'returns file for pac in subdir' do file = double('GitFile') allow(file).to receive(:name).and_return(:'dir::file1') repo = double('GitRepository') expect(repo).to receive(:[]).and_return(file) storage = LocalStorage.new(repo) file = storage.find('dir/file1') expect(file.name).to eq(:'dir::file1') end it 'returns null file if does not exist' do repo = double('GitRepository') expect(repo).to receive(:[]).and_return(nil) storage = LocalStorage.new(repo) expect(storage.find('unexist')).to be_nil end end end end