spec/unit/client_spec.rb in browsermob-proxy-0.1.1 vs spec/unit/client_spec.rb in browsermob-proxy-0.1.2
- old
+ new
@@ -15,11 +15,12 @@
"har/pageRef" => double("resource[har/pageRef]"),
"whitelist" => double("resource[whitelist]"),
"blacklist" => double("resource[blacklist]"),
"limit" => double("resource[limit]"),
"headers" => double("resource[headers]"),
- "auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]")
+ "auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]"),
+ "hosts" => double("resource[hosts]")
}.each do |path, mock|
resource.stub(:[]).with(path).and_return(mock)
end
end
@@ -82,15 +83,31 @@
with(:regex => "http://example.com", :status => 401)
client.blacklist(%r[http://example.com], 401)
end
- it "sets the whitelist" do
- resource['whitelist'].should_receive(:put).
- with(:regex => "http://example.com", :status => 401)
+ describe 'whitelist' do
+ it "supports a string" do
+ resource['whitelist'].should_receive(:put).
+ with(:regex => 'https?://example\.com', :status => 401)
- client.whitelist(%r[http://example.com], 401)
+ client.whitelist('https?://example\.com', 401)
+ end
+
+ it "supports a regexp" do
+ resource['whitelist'].should_receive(:put).
+ with(:regex => 'https?://example\.com', :status => 401)
+
+ client.whitelist(%r{https?://example\.com}, 401)
+ end
+
+ it "supports an array of regexps and strings" do
+ 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
end
it "sets the :downstream_kbps limit" do
resource['limit'].should_receive(:put).
with('downstreamKbps' => 100)
@@ -133,9 +150,16 @@
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
+
+ it 'sets mapped dns hosts' do
+ resource['hosts'].should_receive(:post).with(%({"#{DOMAIN}":"1.2.3.4"}),
+ :content_type => "application/json")
+
+ client.remap_dns_hosts(DOMAIN => '1.2.3.4')
end
context "#selenium_proxy" do
it "defaults to HTTP proxy only" do
proxy = client.selenium_proxy