# encoding: utf-8 require 'spec_helper' require 'spec_helper_features' describe 'Fetch proxy pac' do context '/v1/pac' do let(:valid_pac_file) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { return "DIRECT"; } EOS end let(:pac_file_return_nil) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { return ""; } EOS end let(:invalid_pac_file) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { asdfasdf(); } EOS end let(:git_repo) { 'git_repo' } before(:each) do git_init(git_repo) create_file(File.join(git_repo, 'file.pac'), valid_pac_file) git_add(git_repo, 'file.pac') git_commit(git_repo) end before :each do config = Class.new do include FeduxOrg::Stdlib::Filesystem def root_directory File.expand_path('../../../', __FILE__) end def local_storage File.join(working_directory, 'git_repo', '.git') end end.new LocalPac.config = config Capybara.app = LocalPac::App::LookupController end it 'looks up proxy', :focus do visit('/file.pac') within('#search') do fill_in 'url', :with => 'http://www.example.org' end expect(page).to have_content('asdf') end it 'shows a result output' do rendered_view = <<-EOS.strip_heredoc EOS response = post('/file.pac', {:url => 'http://example.org'}) expect(last_response).to be_ok expect(response.body).to eq('Please enter fully quallified url') end it 'handles a nil file as well' do create_file(File.join(git_repo, 'file_nil.pac'), pac_file_return_nil) git_add(git_repo, 'file_nil.pac') git_commit(git_repo) rendered_view = <<-EOS.strip_heredoc EOS response = post('/file_nil.pac', {:url => 'http://example.org'}) expect(last_response).to be_ok expect(response.body).to eq(rendered_view) end it 'raises an exception on invalid pac file' do create_file(File.join(git_repo, 'invalid.pac'), invalid_pac_file) git_add(git_repo, 'invalid.pac') git_commit(git_repo) expect { response = post('/invalid.pac', {:url => 'http://example.org'}) }.to raise_error RuntimeError end it 'returns a result for an existing proxy pac' do pending end it 'returns a error if file does not exist' do pending end end end