# encoding: utf-8 require 'spec_helper' require 'spec_helper_features' describe 'Lookup proxy for url' do context '/v1/lookup' 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) git_set_author(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 for valid url' do search_for 'http://www.example.org', 'You asked me to look up' end it 'returns a error message for a invalid url' do visit('/file.pac') within('#search') do fill_in 'url', :with => '§ASDF$$' end click_on('Search') expect(page).to have_content('Invalid URL...') end it 'returns a error message for a invalid url on the second page' do visit('/file.pac') within('#search') do fill_in 'url', :with => 'http://www.example.org' end click_on('Search') within('#search') do fill_in 'url', :with => '§ASDF$$' end click_on('Search') expect(page).to have_content('Invalid URL...') end it 'returns a error message for a invalid url' do visit('/file.pac') within('#search') do fill_in 'url', :with => '' end click_on('Search') expect(page).to have_content('Invalid URL...') end end end