puffing-billy 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -2
- data/lib/billy.rb +14 -0
- data/lib/billy/proxy_request_stub.rb +1 -11
- data/lib/billy/version.rb +1 -1
- data/spec/features/examples/tumblr_api_spec.rb +49 -19
- data/spec/lib/billy/proxy_request_stub_spec.rb +2 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b6481a511001f8deb9af5c1e00a4a3a4b91e96cb1bd7b039ef25e2685e70930
|
4
|
+
data.tar.gz: 037f87e67fc52e5798e3024947f36b5233cd017429589eccda6993691d6529de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fe9255112bc4031b859f6a0ad016a6f9c7a2fcef38176ff6a60804f3068e3309e3798be59f6bd1e9fa5dd814753bf6a4b42e541cb46919021d2f4126628a1db
|
7
|
+
data.tar.gz: 6f081f4ec79141bc5ea1d349d12f1edfe219faaec27cec3eeebd3327683a07b994b1c3960f3227b49974538445093475375dd0378332c2c908d22ed803e5ba2d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
v1.1.1, 2018-05-12
|
2
|
+
-------------------
|
3
|
+
* Fix scope breaking change of request/response interception [#242](https://github.com/oesmith/puffing-billy/pull/242)
|
4
|
+
|
1
5
|
v1.1.0, 2018-04-29
|
2
6
|
-------------------
|
3
7
|
* Expose stub instances via puffing billy [#224](https://github.com/oesmith/puffing-billy/pull/224)
|
data/README.md
CHANGED
@@ -115,9 +115,10 @@ proxy.stub('https://example.com/proc/').and_return(Proc.new { |params, headers,
|
|
115
115
|
# You can also use Puffing Billy to intercept requests and responses. Just pass
|
116
116
|
# a Proc and use the pass_request method. You can manipulate the request
|
117
117
|
# (headers, URL, HTTP method, etc) and also the response from the upstream
|
118
|
-
# server.
|
118
|
+
# server. The scope of the delivered callable is the user scope where
|
119
|
+
# it was defined.
|
119
120
|
proxy.stub('http://example.com/').and_return(Proc.new { |*args|
|
120
|
-
response = pass_request(*args)
|
121
|
+
response = Billy.pass_request(*args)
|
121
122
|
response[:headers]['Content-Type'] = 'text/plain'
|
122
123
|
response[:body] = 'Hello World!'
|
123
124
|
response[:code] = 200
|
data/lib/billy.rb
CHANGED
@@ -28,4 +28,18 @@ module Billy
|
|
28
28
|
def self.certificate_authority
|
29
29
|
@certificate_authority ||= Billy::Authority.new
|
30
30
|
end
|
31
|
+
|
32
|
+
# This global shortcut can be used inside of request stubs. You can modify
|
33
|
+
# the request beforehand and/or modify the actual response which is passed
|
34
|
+
# back by this method. But you can also implement a custom proxy passing
|
35
|
+
# method if you like to. This is just a shortcut.
|
36
|
+
def self.pass_request(params, headers, body, url, method)
|
37
|
+
handler = proxy.request_handler.handlers[:proxy]
|
38
|
+
response = handler.handle_request(method, url, headers, body)
|
39
|
+
{
|
40
|
+
code: response[:status],
|
41
|
+
body: response[:content],
|
42
|
+
headers: response[:headers]
|
43
|
+
}
|
44
|
+
end
|
31
45
|
end
|
@@ -21,7 +21,7 @@ module Billy
|
|
21
21
|
push_request(method, url, params, headers, body)
|
22
22
|
|
23
23
|
if @response.respond_to?(:call)
|
24
|
-
res =
|
24
|
+
res = @response.call(params, headers, body, url, method)
|
25
25
|
else
|
26
26
|
res = @response
|
27
27
|
end
|
@@ -71,16 +71,6 @@ module Billy
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def pass_request(params, headers, body, url, method)
|
75
|
-
handler = Billy.proxy.request_handler.handlers[:proxy]
|
76
|
-
response = handler.handle_request(method, url, headers, body)
|
77
|
-
{
|
78
|
-
code: response[:status],
|
79
|
-
body: response[:content],
|
80
|
-
headers: response[:headers]
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
74
|
private
|
85
75
|
|
86
76
|
attr_writer :requests
|
data/lib/billy/version.rb
CHANGED
@@ -1,24 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
before do
|
5
|
-
proxy.stub('http://blog.howmanyleft.co.uk/api/read/json').and_return(
|
6
|
-
jsonp: {
|
7
|
-
posts: [
|
8
|
-
{
|
9
|
-
'regular-title' => 'News Item 1',
|
10
|
-
'url-with-slug' => 'http://example.com/news/1',
|
11
|
-
'regular-body' => 'News item 1 content here'
|
12
|
-
},
|
13
|
-
{
|
14
|
-
'regular-title' => 'News Item 2',
|
15
|
-
'url-with-slug' => 'http://example.com/news/2',
|
16
|
-
'regular-body' => 'News item 2 content here'
|
17
|
-
}
|
18
|
-
]
|
19
|
-
})
|
20
|
-
end
|
21
|
-
|
3
|
+
RSpec.shared_examples 'tumblr/expectations' do
|
22
4
|
it 'should show news stories' do
|
23
5
|
visit '/tumblr_api.html'
|
24
6
|
expect(page).to have_link('News Item 1', href: 'http://example.com/news/1')
|
@@ -27,3 +9,51 @@ describe 'Tumblr API example', type: :feature, js: true do
|
|
27
9
|
expect(page).to have_content('News item 2 content here')
|
28
10
|
end
|
29
11
|
end
|
12
|
+
|
13
|
+
describe 'Tumblr API example', type: :feature, js: true do
|
14
|
+
context 'without scope external references' do
|
15
|
+
before do
|
16
|
+
proxy.stub('http://blog.howmanyleft.co.uk/api/read/json').and_return(
|
17
|
+
jsonp: {
|
18
|
+
posts: [
|
19
|
+
{
|
20
|
+
'regular-title' => 'News Item 1',
|
21
|
+
'url-with-slug' => 'http://example.com/news/1',
|
22
|
+
'regular-body' => 'News item 1 content here'
|
23
|
+
},
|
24
|
+
{
|
25
|
+
'regular-title' => 'News Item 2',
|
26
|
+
'url-with-slug' => 'http://example.com/news/2',
|
27
|
+
'regular-body' => 'News item 2 content here'
|
28
|
+
}
|
29
|
+
]
|
30
|
+
})
|
31
|
+
end
|
32
|
+
|
33
|
+
include_examples 'tumblr/expectations'
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with scope external references' do
|
37
|
+
let(:posts) do
|
38
|
+
[
|
39
|
+
{
|
40
|
+
'regular-title' => 'News Item 1',
|
41
|
+
'url-with-slug' => 'http://example.com/news/1',
|
42
|
+
'regular-body' => 'News item 1 content here'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
'regular-title' => 'News Item 2',
|
46
|
+
'url-with-slug' => 'http://example.com/news/2',
|
47
|
+
'regular-body' => 'News item 2 content here'
|
48
|
+
}
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
before do
|
53
|
+
proxy.stub('http://blog.howmanyleft.co.uk/api/read/json')
|
54
|
+
.and_return(proc { { jsonp: { posts: posts } } })
|
55
|
+
end
|
56
|
+
|
57
|
+
include_examples 'tumblr/expectations'
|
58
|
+
end
|
59
|
+
end
|
@@ -157,9 +157,6 @@ describe Billy::ProxyRequestStub do
|
|
157
157
|
expected_headers = { 'header1' => 'three', 'header2' => 'four' }
|
158
158
|
expected_body = 'body text'
|
159
159
|
|
160
|
-
# Required due to the instance_exec implementation
|
161
|
-
subject.extend(RSpec::Matchers)
|
162
|
-
|
163
160
|
subject.and_return(proc do |params, headers, body, url, method|
|
164
161
|
expect(params).to eql expected_params
|
165
162
|
expect(headers).to eql expected_headers
|
@@ -175,15 +172,12 @@ describe Billy::ProxyRequestStub do
|
|
175
172
|
]
|
176
173
|
end
|
177
174
|
|
178
|
-
it 'should use a callable with pass_request' do
|
175
|
+
it 'should use a callable with Billy.pass_request' do
|
179
176
|
# Add the missing em-synchrony call which is done by
|
180
177
|
# ProxyConnection#handle_request instead.
|
181
178
|
EM.synchrony do
|
182
|
-
# Required due to the instance_exec implementation
|
183
|
-
subject.extend(RSpec::Matchers)
|
184
|
-
|
185
179
|
subject.and_return(proc do |*args|
|
186
|
-
response = pass_request(*args)
|
180
|
+
response = Billy.pass_request(*args)
|
187
181
|
response[:body] = 'modified'
|
188
182
|
response[:code] = 205
|
189
183
|
response
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puffing-billy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olly Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|