spec/unit/client_spec.rb in browsermob-proxy-0.1.6 vs spec/unit/client_spec.rb in browsermob-proxy-0.1.7
- old
+ new
@@ -17,11 +17,12 @@
"blacklist" => double("resource[blacklist]"),
"limit" => double("resource[limit]"),
"headers" => double("resource[headers]"),
"auth/basic/#{DOMAIN}" => double("resource[auth/basic/#{DOMAIN}]"),
"hosts" => double("resource[hosts]"),
- "timeout" => double("resource[timeout]")
+ "timeout" => double("resource[timeout]"),
+ "rewrite" => double("resource[rewrite]")
}.each do |path, mock|
resource.stub(:[]).with(path).and_return(mock)
end
end
@@ -228,9 +229,37 @@
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
+
+ describe 'rewrite rules' do
+
+ context 'when using a regular expression' do
+ it 'sets a rewrite rule' do
+ resource['rewrite'].should_receive(:put).
+ with(:matchRegex => 'old\.com', :replace => 'new.com')
+
+ client.rewrite('old\.com', 'new.com')
+ end
+ end
+
+ context 'when using a string' do
+ it 'sets a rewrite rule' do
+ resource['rewrite'].should_receive(:put).
+ with(:matchRegex => 'old\.com', :replace => 'new.com')
+
+ client.rewrite(%r{old\.com}, 'new.com')
+ end
+ end
+
+ it 'clears the rewrite rules' do
+ resource['rewrite'].should_receive(:delete)
+
+ client.clear_rewrites
+ end
+ end
+
context "#selenium_proxy" do
it "defaults to HTTP proxy only" do
proxy = client.selenium_proxy