diff --git a/lib/proxy_fetcher/document/adapters.rb b/lib/proxy_fetcher/document/adapters.rb index 4ef6bb8..fb4bb1b 100644 --- a/lib/proxy_fetcher/document/adapters.rb +++ b/lib/proxy_fetcher/document/adapters.rb @@ -6,6 +6,8 @@ class Adapters class << self def lookup(name_or_class) + raise Exceptions::BlankAdapter if name_or_class.nil? || name_or_class.to_s.empty? + case name_or_class when Symbol, String adapter_name = name_or_class.to_s.capitalize << ADAPTER diff --git a/lib/proxy_fetcher/exceptions.rb b/lib/proxy_fetcher/exceptions.rb index 08ef3b4..6a89e4d 100644 --- a/lib/proxy_fetcher/exceptions.rb +++ b/lib/proxy_fetcher/exceptions.rb @@ -39,6 +39,16 @@ def initialize(name) end end + class BlankAdapter < Error + def initialize(*) + super(<<-MSG.strip.squeeze + you need to specify adapter for HTML parsing: ProxyFetcher.config.adapter = :nokogiri. + You can use one of the predefined adapters (:nokogiri or :oga) or your own implementation. + MSG + ) + end + end + class AdapterSetupError < Error def initialize(adapter_name, reason) adapter = demodulize(adapter_name.remove('Adapter')) diff --git a/lib/proxy_fetcher/providers/http_tunnel.rb b/lib/proxy_fetcher/providers/http_tunnel.rb index f42dd42..ed991b5 100644 --- a/lib/proxy_fetcher/providers/http_tunnel.rb +++ b/lib/proxy_fetcher/providers/http_tunnel.rb @@ -1,5 +1,3 @@ -require 'irb' - module ProxyFetcher module Providers class HTTPTunnel < Base diff --git a/proxy_fetcher.gemspec b/proxy_fetcher.gemspec index 16f7ea3..a53640d 100644 --- a/proxy_fetcher.gemspec +++ b/proxy_fetcher.gemspec @@ -5,10 +5,10 @@ require 'proxy_fetcher/version' Gem::Specification.new do |gem| gem.name = 'proxy_fetcher' gem.version = ProxyFetcher.gem_version - gem.date = '2017-11-13' + gem.date = '2017-12-05' gem.summary = 'Ruby gem for dealing with proxy lists from different providers' gem.description = 'This gem can help your Ruby application to make HTTP(S) requests ' \ - 'from proxy server by fetching and validating proxy lists from the different providers.' + 'using proxies by fetching and validating proxy lists from the different providers.' gem.authors = ['Nikita Bulai'] gem.email = 'bulajnikita@gmail.com' gem.require_paths = ['lib'] diff --git a/spec/proxy_fetcher/document/adapters_spec.rb b/spec/proxy_fetcher/document/adapters_spec.rb index 5b18683..f203846 100644 --- a/spec/proxy_fetcher/document/adapters_spec.rb +++ b/spec/proxy_fetcher/document/adapters_spec.rb @@ -12,6 +12,11 @@ expect(described_class.lookup(Struct)).to eq(Struct) end + it 'raises an exception if passed value is blank' do + expect { described_class.lookup(nil) }.to raise_error(ProxyFetcher::Exceptions::BlankAdapter) + expect { described_class.lookup('') }.to raise_error(ProxyFetcher::Exceptions::BlankAdapter) + end + it "raises an exception if adapter doesn't exist" do expect { described_class.lookup('wrong') }.to raise_error(ProxyFetcher::Exceptions::UnknownAdapter) end