runscope-rb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02a0fc3d67f49af706c3a49c307b89165e850c14
4
- data.tar.gz: 0877e9330940e4632d7069967cb04c87cc1ece01
3
+ metadata.gz: 3fc8642038dfa6f69a61cf84a141b626bbc6e763
4
+ data.tar.gz: 4d8f409e1c8e50c82b7a1ee6e624893b979a13be
5
5
  SHA512:
6
- metadata.gz: 88e0c2104b9fb8b4bdecf3432da22732260102f38d298ab634f98846398d7be1b543cbe3ad2269df535357faaefeb4a329ac081ff8414b6f4f8bf905cb8f5c00
7
- data.tar.gz: f58555248bc025fb441f628db2dd350981acd9772750209ba1b2feb1ee330a60c606f07167b2df4db0224d838e806c56e3ad3c307e4e49418f7fc7b8f611ebc2
6
+ metadata.gz: 49d1c17c412606f283ad46d65fa89f8eebec2e0a8f7b3e0729116956d6c27837a04e1ea13fe747581c0935a9432ae1fab89a2bcebbaba6a6fa3244d0accbb498
7
+ data.tar.gz: faa85b5aca3fed00a512036ad9bb782073883f296c64dea2922748ab53c6b889c9d0bd9945850e39ad4d6ee1fc7af516045e1e95bd8c7226c113b90bd7d78f60
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
19
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # runscope-rb
2
2
 
3
+ [![Dependency Status](https://gemnasium.com/chriswarren/runscope-rb.png)](https://gemnasium.com/chriswarren/runscope-rb)
4
+
3
5
  A gem to quickly get up and running with Runscope in a few lines of code.
4
6
 
5
7
  runscope-rb currently supports Net::HTTP requests. Requests made using other HTTP libraries, such as libcurl or sockets, won't be modified. If you want to add support for another HTTP library that would be fantastic. See the section on Contributing at the end of the readme.
@@ -8,15 +10,15 @@ runscope-rb currently supports Net::HTTP requests. Requests made using other HTT
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
11
- gem 'runscope', '~> 0.0.2'
13
+ gem 'runscope', '~> 0.0.3'
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
17
+ $ bundle
16
18
 
17
19
  Or install it yourself as:
18
20
 
19
- $ gem install runscope
21
+ $ gem install runscope
20
22
 
21
23
  ## Usage
22
24
 
data/lib/ext/net_http.rb CHANGED
@@ -6,12 +6,15 @@ module Net
6
6
 
7
7
  def request_with_runscope(request, body=nil, &block)
8
8
  if ::Runscope.monitor?(self.address)
9
+ if ::Runscope.is_non_standard_port?(@port)
10
+ request = ::Runscope.add_port_header_to_request(request, @port)
11
+ @port = 80
12
+ end
9
13
  @address = ::Runscope.proxy_domain(self.address)
10
14
  end
11
15
  request_without_runscope(request, body, &block)
12
16
  end
13
17
  alias_method :request_without_runscope, :request
14
18
  alias_method :request, :request_with_runscope
15
-
16
19
  end
17
20
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module Runscope
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,5 +1,5 @@
1
- require "runscope/version"
2
- require "runscope/configuration"
1
+ require "runscope-rb/version"
2
+ require "runscope-rb/configuration"
3
3
  require "ext/net_http"
4
4
 
5
5
  module Runscope
@@ -30,6 +30,19 @@ module Runscope
30
30
  "#{subdomain}-#{bucket}.runscope.net"
31
31
  end
32
32
 
33
+ def self.add_port_header_to_request(request, port)
34
+ headers = request.instance_variable_get('@header')
35
+ request.instance_variable_set(
36
+ '@header',
37
+ headers.merge('Runscope-Request-Port' => "#{port}")
38
+ )
39
+ request
40
+ end
41
+
42
+ def self.is_non_standard_port?(port)
43
+ port != 443 && port != 80
44
+ end
45
+
33
46
  def self.enabled?
34
47
  Runscope.enabled
35
48
  end
data/runscope-rb.gemspec CHANGED
@@ -1,8 +1,5 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'runscope'
5
- require 'runscope/version'
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "runscope-rb/version"
6
3
 
7
4
  Gem::Specification.new do |spec|
8
5
  spec.name = "runscope-rb"
@@ -22,6 +19,8 @@ Gem::Specification.new do |spec|
22
19
  spec.add_development_dependency "bundler", "~> 1.3"
23
20
  spec.add_development_dependency "rake"
24
21
  spec.add_development_dependency "rspec", "~>2.13.0"
25
- spec.add_development_dependency "fakeweb", "~> 1.3.0"
22
+ spec.add_development_dependency "webmock", "~> 1.13.0"
26
23
  spec.add_development_dependency "simplecov"
24
+ spec.add_development_dependency "debugger", "~> 1.6.1"
25
+ spec.add_development_dependency "fuubar", "~> 1.1.1"
27
26
  end
@@ -17,20 +17,25 @@ describe Net::HTTP do
17
17
  end
18
18
 
19
19
  context "to a url monitored by runscope" do
20
- it "should modify a to a url that matches a string" do
21
- FakeWeb.register_uri(:get, "http://api-stackexchange-com-#{@bucket}.runscope.net", :body => "test")
20
+ it "modifies a url that matches a string" do
21
+ stub_request(:get, "http://api-stackexchange-com-#{@bucket}.runscope.net")
22
22
  Net::HTTP.get_response(URI.parse("http://api.stackexchange.com"))
23
23
  end
24
24
 
25
- it "should modify a request to a url that matches a regexp" do
26
- FakeWeb.register_uri(:get, "http://test-desk-com-#{@bucket}.runscope.net", :body => "test")
25
+ it "modifies a url that matches a regexp" do
26
+ stub_request(:get, "http://test-desk-com-#{@bucket}.runscope.net")
27
27
  Net::HTTP.get_response(URI.parse("http://test.desk.com"))
28
28
  end
29
+
30
+ it "sets a header if the url specifies a port" do
31
+ stub_request(:get, "http://test-desk-com-#{@bucket}.runscope.net").with(headers: {'Runscope-Request-Port' => 401})
32
+ Net::HTTP.get_response(URI.parse("http://test.desk.com:401"))
33
+ end
29
34
  end
30
35
 
31
36
  context "to a url not monitored by runscope" do
32
- it "should not modify a request to a url that doesn't match" do
33
- FakeWeb.register_uri(:get, "http://api.twitter.com", :body => "test")
37
+ it "doesn't modify a url that doesn't match" do
38
+ stub_request(:any, "http://api.twitter.com")
34
39
  Net::HTTP.get_response(URI.parse("http://api.twitter.com"))
35
40
  end
36
41
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Runscope::Configuration do
4
+ let(:domains){["api.stackexchange.com", /\S+\.desk\.com/]}
5
+ let(:bucket){"1234abcd"}
6
+
7
+ before(:each) do
8
+ Runscope.configure do |config|
9
+ config.domains = domains
10
+ config.bucket = bucket
11
+ end
12
+ end
13
+
14
+ after(:each) do
15
+ Runscope.reset
16
+ end
17
+
18
+ it{expect(Runscope.enabled).to eq(true)}
19
+ it{expect(Runscope.domains).to eq(domains)}
20
+ it{expect(Runscope.bucket).to eq(bucket)}
21
+
22
+ it{expect(Runscope.options).to include({bucket: bucket})}
23
+ it{expect(Runscope.options).to include({domains: domains})}
24
+ it{expect(Runscope.options).to include({enabled: true})}
25
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Runscope do
4
+ describe '#version_string' do
5
+ it 'should return correct version string' do
6
+ Runscope.version_string.should eq("Runscope version #{Runscope::VERSION}")
7
+ end
8
+ end
9
+
10
+ describe '#monitor?' do
11
+ before(:each){
12
+ Runscope.domains = ["api.stackexchange.com", /\S+\.desk\.com/]
13
+ }
14
+ after(:each){ Runscope.reset }
15
+ context "when enabled" do
16
+ before{ Runscope.enabled = true }
17
+ it{expect(Runscope.monitor?("api.stackexchange.com")).to eq(true)}
18
+ it{expect(Runscope.monitor?("api.twitter.com")).to eq(false)}
19
+ end
20
+
21
+ context "when disabled" do
22
+ before(:each){ Runscope.enabled = false }
23
+ it{expect(Runscope.monitor?("api.stackexchange.com")).to eq(false)}
24
+ it{expect(Runscope.monitor?("api.twitter.com")).to eq(false)}
25
+ end
26
+ end
27
+
28
+ describe '#monitor_domain?' do
29
+ before(:each){
30
+ Runscope.domains = ["api.stackexchange.com", /\S+\.desk\.com/]
31
+ }
32
+
33
+ it{expect(Runscope.monitor_domain?("api.stackexchange.com")).to eq(true)}
34
+ it{expect(Runscope.monitor_domain?("test.desk.com")).to eq(true)}
35
+ it{expect(Runscope.monitor_domain?("api.twitter.com")).to eq(false)}
36
+ it "should raise an error if no domains are set" do
37
+ Runscope.domains = nil
38
+ expect {Runscope.monitor_domain?("api.stackexchange.com")}.to(
39
+ raise_error(NoDomainsSetError)
40
+ )
41
+ end
42
+ end
43
+
44
+ describe '#proxy_domain' do
45
+ before(:each) do
46
+ @bucket = "1234abcd"
47
+ Runscope.bucket = @bucket
48
+ end
49
+
50
+ it{expect(Runscope.proxy_domain("api.stackexchange.com")).to(
51
+ eq("api-stackexchange-com-#{@bucket}.runscope.net")
52
+ )}
53
+
54
+ it "should raise an error if no bucket is set" do
55
+ Runscope.bucket = nil
56
+ expect {
57
+ Runscope.proxy_domain("api.stackexchange.com")
58
+ }.to raise_error(BucketNotSetError)
59
+ end
60
+ end
61
+
62
+ describe '#add_port_header_to_request' do
63
+ let(:port){ 4000 }
64
+ let(:request){ Net::HTTP::Get.new('http://example.com') }
65
+ it 'sets the Runscope-Request-Port header' do
66
+ modified_request = Runscope.add_port_header_to_request(request, port)
67
+ expect(modified_request.instance_variable_get('@header')).to(
68
+ include({'Runscope-Request-Port' => "#{port}"})
69
+ )
70
+ end
71
+ end
72
+
73
+ describe '#is_non_standard_port?' do
74
+ it{expect(Runscope.is_non_standard_port?(80)).to be_false}
75
+ it{expect(Runscope.is_non_standard_port?(443)).to be_false}
76
+ it{expect(Runscope.is_non_standard_port?(6000)).to be_true}
77
+ end
78
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,13 +2,10 @@ require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
4
  require 'rspec'
5
- require 'fakeweb'
6
- require 'runscope'
5
+ require 'webmock/rspec'
6
+ require 'runscope-rb'
7
7
 
8
8
  RSpec.configure do |config|
9
9
  config.color_enabled = true
10
- config.formatter = 'documentation'
11
10
  config.order = "random"
12
11
  end
13
-
14
- FakeWeb.allow_net_connect = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runscope-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Warren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.13.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: fakeweb
56
+ name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.0
61
+ version: 1.13.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.0
68
+ version: 1.13.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: debugger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: fuubar
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.1
83
111
  description: Start using Runscope to monitor your API traffic in minutes
84
112
  email:
85
113
  - chris@expectless.com
@@ -88,18 +116,19 @@ extensions: []
88
116
  extra_rdoc_files: []
89
117
  files:
90
118
  - .gitignore
119
+ - .rspec
91
120
  - Gemfile
92
121
  - LICENSE.txt
93
122
  - README.md
94
123
  - Rakefile
95
124
  - lib/ext/net_http.rb
96
- - lib/runscope.rb
97
- - lib/runscope/configuration.rb
98
- - lib/runscope/version.rb
125
+ - lib/runscope-rb.rb
126
+ - lib/runscope-rb/configuration.rb
127
+ - lib/runscope-rb/version.rb
99
128
  - runscope-rb.gemspec
100
129
  - spec/ext/net_http_spec.rb
101
- - spec/runscope/configuration_spec.rb
102
- - spec/runscope_spec.rb
130
+ - spec/runscope-rb/configuration_spec.rb
131
+ - spec/runscope-rb_spec.rb
103
132
  - spec/spec_helper.rb
104
133
  homepage: http://github.com/chriswarren/runscope-rb
105
134
  licenses:
@@ -127,6 +156,6 @@ specification_version: 4
127
156
  summary: Start using Runscope to monitor your API traffic in minutes
128
157
  test_files:
129
158
  - spec/ext/net_http_spec.rb
130
- - spec/runscope/configuration_spec.rb
131
- - spec/runscope_spec.rb
159
+ - spec/runscope-rb/configuration_spec.rb
160
+ - spec/runscope-rb_spec.rb
132
161
  - spec/spec_helper.rb
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Runscope::Configuration do
4
- after(:each) do
5
- Runscope.reset
6
- end
7
-
8
- it 'should set options when passed a block' do
9
- domains = ["api.stackexchange.com", /\S+\.desk\.com/]
10
- bucket = "1234abcd"
11
-
12
- Runscope.configure do |config|
13
- config.domains = domains
14
- config.bucket = bucket
15
- end
16
-
17
- Runscope.enabled.should eq(true)
18
- Runscope.domains.should eq(domains)
19
- Runscope.bucket.should eq(bucket)
20
- end
21
- end
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Runscope do
4
- context "basic methods" do
5
- it 'should return correct version string' do
6
- Runscope.version_string.should eq("Runscope version #{Runscope::VERSION}")
7
- end
8
- end
9
-
10
- context 'monitoring' do
11
- before(:each) do
12
- Runscope.domains = ["api.stackexchange.com", /\S+\.desk\.com/]
13
- end
14
-
15
- after(:each) do
16
- Runscope.reset
17
- end
18
-
19
- context "when enabled" do
20
- before(:each) do
21
- Runscope.enabled = true
22
- end
23
-
24
- it "should be true if the domain is monitored" do
25
- Runscope.monitor?("api.stackexchange.com").should eq(true)
26
- end
27
-
28
- it "should be false if the domain is not monitored" do
29
- Runscope.monitor?("api.twitter.com").should eq(false)
30
- end
31
- end
32
-
33
- context "when disabled" do
34
- before(:each) do
35
- Runscope.enabled = false
36
- end
37
-
38
- it "should be false if the domain is monitored" do
39
- Runscope.monitor?("api.stackexchange.com").should eq(false)
40
- end
41
-
42
- it "should be false if the domain is not monitored" do
43
- Runscope.monitor?("api.twitter.com").should eq(false)
44
- end
45
- end
46
- end
47
-
48
- context 'matching domains' do
49
- before(:each) do
50
- Runscope.domains = ["api.stackexchange.com", /\S+\.desk\.com/]
51
- end
52
-
53
- it "should match when stored as a string" do
54
- Runscope.monitor_domain?("api.stackexchange.com").should eq(true)
55
- end
56
-
57
- it "should match when stored as a Regexp" do
58
- Runscope.monitor_domain?("test.desk.com").should eq(true)
59
- end
60
-
61
- it "should not match domains that aren't set" do
62
- Runscope.monitor_domain?("api.twitter.com").should eq(false)
63
- end
64
-
65
- it "should raise an error if no domains are set" do
66
- Runscope.domains = nil
67
- expect {
68
- Runscope.monitor_domain?("api.stackexchange.com")
69
- }.to raise_error(NoDomainsSetError)
70
- end
71
- end
72
-
73
- context 'generating a runscope proxy domain' do
74
- before(:each) do
75
- @bucket = "1234abcd"
76
- Runscope.bucket = @bucket
77
- end
78
-
79
- it "should return a domain to runscope" do
80
- Runscope.proxy_domain("api.stackexchange.com").should
81
- eq("api-stackexchange-com-#{@bucket}.runscope.net")
82
- end
83
-
84
- it "should raise an error if no bucket is set" do
85
- Runscope.bucket = nil
86
- expect {
87
- Runscope.proxy_domain("api.stackexchange.com")
88
- }.to raise_error(BucketNotSetError)
89
- end
90
- end
91
- end