browsermob-proxy 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,6 +2,20 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new
5
+
6
+ namespace :spec do
7
+ desc 'Run unit specs.'
8
+ RSpec::Core::RakeTask.new(:unit) do |t|
9
+ t.pattern = "spec/unit/*_spec.rb"
10
+ end
11
+
12
+ desc 'Run end to end specs.'
13
+ RSpec::Core::RakeTask.new(:e2e) do |t|
14
+ t.pattern = "spec/e2e/*_spec.rb"
15
+ end
16
+ end
17
+
18
+ desc 'Run all specs.'
19
+ task :spec => %w[spec:unit spec:e2e]
6
20
 
7
21
  task :default => :spec
@@ -41,18 +41,42 @@ module BrowserMob
41
41
 
42
42
  def whitelist(regexp, status_code)
43
43
  regex = Regexp === regexp ? regexp.source : regexp.to_s
44
- @resource['har/whitelist'].put :regex => regex, :status => status_code
44
+ @resource['whitelist'].put :regex => regex, :status => status_code
45
45
  end
46
46
 
47
47
  def blacklist(regexp, status_code)
48
48
  regex = Regexp === regexp ? regexp.source : regexp.to_s
49
- @resource['har/blacklist'].put :regex => regex, :status => status_code
49
+ @resource['blacklist'].put :regex => regex, :status => status_code
50
+ end
51
+
52
+ LIMITS = {
53
+ :upstream_kbps => 'upstreamKbps',
54
+ :downstream_kbps => 'downstreamKbps',
55
+ :latency => 'latency'
56
+ }
57
+
58
+ def limit(opts)
59
+ params = {}
60
+
61
+ opts.each do |key, value|
62
+ unless LIMITS.member?(key)
63
+ raise ArgumentError, "invalid: #{key.inspect} (valid options: #{LIMITS.keys.inspect})"
64
+ end
65
+
66
+ params[LIMITS[key]] = Integer(value)
67
+ end
68
+
69
+ if params.empty?
70
+ raise ArgumentError, "must specify one of #{LIMITS.keys.inspect}"
71
+ end
72
+
73
+ @resource['limit'].put params
50
74
  end
51
75
 
52
76
  def close
53
77
  @resource.delete
54
78
  end
55
- end
79
+ end # Client
56
80
 
57
- end
58
- end
81
+ end # Proxy
82
+ end # BrowserMob
@@ -1,5 +1,5 @@
1
1
  module BrowserMob
2
2
  module Proxy
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Proxy + WebDriverListener" do
4
- let(:wait) { Selenium::WebDriver::Wait.new }
4
+ let(:proxy) { new_proxy }
5
5
  let(:listener) { BrowserMob::Proxy::WebDriverListener.new(proxy) }
6
+
6
7
  let(:driver) { Selenium::WebDriver.for :firefox, :profile => profile, :listener => listener }
7
- let(:proxy) { new_proxy }
8
+ let(:wait) { Selenium::WebDriver::Wait.new }
8
9
 
9
10
  let(:profile) {
10
11
  pr = Selenium::WebDriver::Firefox::Profile.new
@@ -13,9 +14,7 @@ describe "Proxy + WebDriverListener" do
13
14
  pr
14
15
  }
15
16
 
16
- after {
17
- proxy.close
18
- }
17
+ after { proxy.close }
19
18
 
20
19
  it "should record events" do
21
20
  driver.get url_for("1.html")
@@ -26,7 +25,5 @@ describe "Proxy + WebDriverListener" do
26
25
  hars.size.should == 1
27
26
 
28
27
  hars.first.pages.size.should == 2
29
-
30
- hars.each_with_index { |e,i| e.save_to("/tmp/#{i}.har") }
31
28
  end
32
29
  end
@@ -28,4 +28,14 @@ describe "Proxy + WebDriver" do
28
28
  har.should be_kind_of(HAR::Archive)
29
29
  har.pages.size.should == 2
30
30
  end
31
+
32
+ it "should set whitelist and blacklist" do
33
+ proxy.whitelist(/example\.com/, 201)
34
+ proxy.blacklist(/bad\.com/, 404)
35
+ end
36
+
37
+ it "should set limits" do
38
+ proxy.limit(:downstream_kbps => 100, :upstream_kbps => 100, :latency => 2)
39
+ end
40
+
31
41
  end
@@ -9,10 +9,11 @@ module BrowserMob
9
9
 
10
10
  before do
11
11
  {
12
- "har" => mock("resource[har]"),
13
- "har/pageRef" => mock("resource[har/pageRef]"),
14
- "har/whitelist" => mock("resource[har/whitelist]"),
15
- "har/blacklist" => mock("resource[har/blacklist]")
12
+ "har" => mock("resource[har]"),
13
+ "har/pageRef" => mock("resource[har/pageRef]"),
14
+ "whitelist" => mock("resource[whitelist]"),
15
+ "blacklist" => mock("resource[blacklist]"),
16
+ "limit" => mock("resource[limit]")
16
17
  }.each do |path, mock|
17
18
  resource.stub!(:[]).with(path).and_return(mock)
18
19
  end
@@ -49,18 +50,51 @@ module BrowserMob
49
50
  end
50
51
 
51
52
  it "sets the blacklist" do
52
- resource['har/blacklist'].should_receive(:put).
53
- with(:regex => "http://example.com", :status => 401)
53
+ resource['blacklist'].should_receive(:put).
54
+ with(:regex => "http://example.com", :status => 401)
54
55
 
55
56
  client.blacklist(%r[http://example.com], 401)
56
57
  end
57
58
 
58
59
  it "sets the whitelist" do
59
- resource['har/whitelist'].should_receive(:put).
60
- with(:regex => "http://example.com", :status => 401)
60
+ resource['whitelist'].should_receive(:put).
61
+ with(:regex => "http://example.com", :status => 401)
61
62
 
62
63
  client.whitelist(%r[http://example.com], 401)
63
64
  end
65
+
66
+ it "sets the :downstream_kbps limit" do
67
+ resource['limit'].should_receive(:put).
68
+ with('downstreamKbps' => 100)
69
+
70
+ client.limit(:downstream_kbps => 100)
71
+ end
72
+
73
+ it "sets the :upstream_kbps limit" do
74
+ resource['limit'].should_receive(:put).
75
+ with('upstreamKbps' => 100)
76
+
77
+ client.limit(:upstream_kbps => 100)
78
+ end
79
+
80
+ it "sets the :latency limit" do
81
+ resource['limit'].should_receive(:put).
82
+ with('latency' => 100)
83
+
84
+ client.limit(:latency => 100)
85
+ end
86
+
87
+ it "sets all limits" do
88
+ resource['limit'].should_receive(:put).
89
+ with('latency' => 100, 'downstreamKbps' => 200, 'upstreamKbps' => 300)
90
+
91
+ client.limit(:latency => 100, :downstream_kbps => 200, :upstream_kbps => 300)
92
+ end
93
+
94
+ it "raises ArgumentError on invalid options" do
95
+ lambda { client.limit(:foo => 1) }.should raise_error(ArgumentError)
96
+ lambda { client.limit({}) }.should raise_error(ArgumentError)
97
+ end
64
98
  end
65
99
 
66
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsermob-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &2161286300 !ruby/object:Gem::Requirement
16
+ requirement: &2153771760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2161286300
24
+ version_requirements: *2153771760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: childprocess
27
- requirement: &2161279940 !ruby/object:Gem::Requirement
27
+ requirement: &2153770220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2161279940
35
+ version_requirements: *2153770220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &2161263620 !ruby/object:Gem::Requirement
38
+ requirement: &2153768980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2161263620
46
+ version_requirements: *2153768980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: har
49
- requirement: &2161262300 !ruby/object:Gem::Requirement
49
+ requirement: &2153767740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2161262300
57
+ version_requirements: *2153767740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &2161259040 !ruby/object:Gem::Requirement
60
+ requirement: &2153751700 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.5.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2161259040
68
+ version_requirements: *2153751700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: selenium-webdriver
71
- requirement: &2161253700 !ruby/object:Gem::Requirement
71
+ requirement: &2153750140 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '2.7'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2161253700
79
+ version_requirements: *2153750140
80
80
  description: Ruby client for the BrowserMob Proxy REST API
81
81
  email:
82
82
  - jari.bakken@gmail.com