spec/unit/client_spec.rb in browsermob-proxy-0.0.9 vs spec/unit/client_spec.rb in browsermob-proxy-0.1.1

- old
+ new

@@ -1,24 +1,27 @@ require 'spec_helper' module BrowserMob module Proxy + DOMAIN = 'example.com' + describe Client do - let(:resource) { mock(RestClient::Resource) } + let(:resource) { double(RestClient::Resource) } let(:client) { Client.new(resource, "localhost", 9091) } before do { - "har" => mock("resource[har]"), - "har/pageRef" => mock("resource[har/pageRef]"), - "whitelist" => mock("resource[whitelist]"), - "blacklist" => mock("resource[blacklist]"), - "limit" => mock("resource[limit]"), - "headers" => mock("resource[headers]") + "har" => double("resource[har]"), + "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}]") }.each do |path, mock| - resource.stub!(:[]).with(path).and_return(mock) + resource.stub(:[]).with(path).and_return(mock) end end it "creates a named har" do resource['har'].should_receive(:put). @@ -123,9 +126,16 @@ it "sets headers" do resource['headers'].should_receive(:post).with('{"foo":"bar"}', :content_type => "application/json") client.headers(:foo => "bar") + end + + 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 context "#selenium_proxy" do it "defaults to HTTP proxy only" do proxy = client.selenium_proxy