# encoding: utf-8 require 'spec_helper' describe ProxyPac::PACEngine do let(:valid_pac_file) do <<-EOS.strip_heredoc function FindProxyForURL(url, host) { return "DIRECT" } EOS end context '#find' do it 'returns a result' do file = double('PacFile') expect(file).to receive(:content).and_return(valid_pac_file) parser = ProxyPac::PACEngine.new(file: file) result = parser.find(Addressable::URI.parse('http://example.org')) expect(result).to eq('DIRECT') end it 'raises an error if pac file is invalid' do file = double('PacFile') allow(file).to receive(:content).and_return('asdfasdf()') parser = ProxyPac::PACEngine.new(file: file) expect do silence(:stderr) do parser.find(Addressable::URI.parse('http://example.org')) end end.to raise_error Exceptions::PacFileInvalid end end end