spec/unit/client_spec.rb in browsermob-proxy-0.1.4 vs spec/unit/client_spec.rb in browsermob-proxy-0.1.5

- old
+ new

@@ -16,11 +16,12 @@ "whitelist" => double("resource[whitelist]"), "blacklist" => double("resource[blacklist]"), "limit" => double("resource[limit]"), "headers" => double("resource[headers]"), "auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]"), - "hosts" => double("resource[hosts]") + "hosts" => double("resource[hosts]"), + "timeout" => double("resource[timeout]") }.each do |path, mock| resource.stub(:[]).with(path).and_return(mock) end end @@ -118,10 +119,16 @@ with(:regex => "http://example.com", :status => 401) client.blacklist(%r[http://example.com], 401) end + it "clears the blacklist" do + resource['blacklist'].should_receive(:delete) + + client.clear_blacklist + end + describe 'whitelist' do it "supports a string" do resource['whitelist'].should_receive(:put). with(:regex => 'https?://example\.com', :status => 401) @@ -139,10 +146,16 @@ resource['whitelist'].should_receive(:put). with(:regex => 'http://example\.com/1/.+,http://example\.com/2/.+', :status => 401) client.whitelist([%r{http://example\.com/1/.+}, 'http://example\.com/2/.+'], 401) end + + it "clears the whitelist" do + resource['whitelist'].should_receive(:delete) + + client.clear_whitelist + end end it "sets the :downstream_kbps limit" do resource['limit'].should_receive(:put). with('downstreamKbps' => 100) @@ -185,9 +198,31 @@ it 'sets basic authentication' do user, password = 'user', 'pass' resource["auth/basic/#{DOMAIN}"].should_receive(:post).with(%({"username":"#{user}","password":"#{password}"}), :content_type => "application/json") client.basic_authentication(DOMAIN, user, password) + end + + describe 'timeouts' do + it 'supports valid options' do + resource['timeout'].should_receive(:put).with( + :requestTimeout => 1, + :readTimeout => 2000, + :connectionTimeout => 3000, + :dnsCacheTimeout => 6_000_000 + ) + + client.timeouts( + :request => 0.001, + :read => 2, + :connection => 3, + :dns_cache => 6000 + ) + end + + it 'raises ArgumentError when invalid options are passed' do + expect { client.timeouts(:invalid => 2) }.to raise_error(ArgumentError, "invalid key: :invalid, should belong to: [:request, :read, :connection, :dns_cache]") + end end it 'sets mapped dns hosts' do resource['hosts'].should_receive(:post).with(%({"#{DOMAIN}":"1.2.3.4"}), :content_type => "application/json")