# 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) allow(file).to receive(:path).and_return('file1.pac') 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 end context '#find' do it 'returns file if exists' do file = double('File') allow(file).to receive(:name).and_return(:file1) allow(file).to receive(:path).and_return('file1.pac') 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('File') allow(file).to receive(:name).and_return(:'dir::file1') allow(file).to receive(:path).and_return('dir/file1.pac') 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 file = double('File') allow(file).to receive(:path).and_return(nil) repo = double('GitRepository') expect(repo).to receive(:[]).and_return(file) storage = LocalStorage.new(repo) expect(storage.find('unexist').path).to be_nil end it 'supports "_" in requested file name' do file = double('File') allow(file).to receive(:name).and_return(:file_pac1) allow(file).to receive(:path).and_return('file_pac1.pac') repo = double('GitRepository') expect(repo).to receive(:[]).with(:file_pac1).and_return(file) storage = LocalStorage.new(repo) file = storage.find('file_pac1') expect(file.name).to eq(:'file_pac1') end end end