webmock 1.8.9 → 1.8.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -0
- data/README.md +1 -0
- data/Rakefile +1 -1
- data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_0_x.rb +2 -2
- data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb +4 -2
- data/lib/webmock/http_lib_adapters/net_http.rb +8 -0
- data/lib/webmock/version.rb +1 -1
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +72 -6
- data/spec/acceptance/net_http/net_http_spec.rb +13 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.8.10
|
4
|
+
|
5
|
+
* em-http-request fix. After request callbacks are correctly invoked for 3xx responses,
|
6
|
+
when :redirects option is set.
|
7
|
+
|
8
|
+
Thanks to [Myron Marston](https://github.com/myronmarston) for reporting that issue.
|
9
|
+
|
10
|
+
* Fixed compatibility with Net::HTTP::DigestAuth
|
11
|
+
|
12
|
+
Thanks to [Jonathan Hyman](https://github.com/jonhyman) for reporting that issue.
|
13
|
+
|
14
|
+
* Fixed problem in em-http-request 0.x appending the query to the client URI twice.
|
15
|
+
|
16
|
+
Thanks to [Paweł Pierzchała](https://github.com/wrozka)
|
17
|
+
|
3
18
|
## 1.8.9
|
4
19
|
|
5
20
|
* Fixed problem with caching nil responses when the same HTTPClient instance is used.
|
data/README.md
CHANGED
@@ -713,6 +713,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
713
713
|
* Kevin Glowacz
|
714
714
|
* Hans Hasselberg
|
715
715
|
* Andrew France
|
716
|
+
* Jonathan Hyman
|
716
717
|
|
717
718
|
For a full list of contributors you can visit the
|
718
719
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/Rakefile
CHANGED
@@ -27,7 +27,7 @@ end
|
|
27
27
|
|
28
28
|
|
29
29
|
task :em_http_request_0_x_spec do
|
30
|
-
sh "EM_HTTP_REQUEST_0_X=true bundle install && bundle exec rspec spec/acceptance/em_http_request/em_http_request_spec.rb" if RUBY_VERSION <= "1.8.7"
|
30
|
+
sh "EM_HTTP_REQUEST_0_X=true bundle install && EM_HTTP_REQUEST_0_X=true bundle exec rspec spec/acceptance/em_http_request/em_http_request_spec.rb" if RUBY_VERSION <= "1.8.7"
|
31
31
|
end
|
32
32
|
|
33
33
|
require 'rake/testtask'
|
@@ -90,11 +90,11 @@ if defined?(EventMachine::HttpRequest)
|
|
90
90
|
if @req
|
91
91
|
options = @req.options
|
92
92
|
method = @req.method
|
93
|
-
uri = @req.uri
|
93
|
+
uri = @req.uri.dup
|
94
94
|
else
|
95
95
|
options = @options
|
96
96
|
method = @method
|
97
|
-
uri = @uri
|
97
|
+
uri = @uri.dup
|
98
98
|
end
|
99
99
|
|
100
100
|
if options[:authorization] || options['authorization']
|
@@ -108,14 +108,16 @@ if defined?(EventMachine::HttpClient)
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
def
|
112
|
-
if
|
111
|
+
def unbind(reason = nil)
|
112
|
+
if !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
|
113
113
|
webmock_response = build_webmock_response
|
114
114
|
WebMock::CallbackRegistry.invoke_callbacks(
|
115
115
|
{:lib => :em_http_request, :real_request => true},
|
116
116
|
request_signature,
|
117
117
|
webmock_response)
|
118
118
|
end
|
119
|
+
@request_signature = nil
|
120
|
+
remove_instance_variable(:@stubbed_webmock_response)
|
119
121
|
|
120
122
|
super
|
121
123
|
end
|
@@ -28,6 +28,14 @@ module WebMock
|
|
28
28
|
Net.send(:const_set, :HTTP, OriginalNetHTTP)
|
29
29
|
Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
|
30
30
|
Net.send(:const_set, :BufferedIO, OriginalNetBufferedIO)
|
31
|
+
|
32
|
+
#copy all constants from @webMockNetHTTP to original Net::HTTP
|
33
|
+
#in case any constants were added to @webMockNetHTTP instead of Net::HTTP
|
34
|
+
#after WebMock was enabled.
|
35
|
+
#i.e Net::HTTP::DigestAuth
|
36
|
+
(@webMockNetHTTP.constants - OriginalNetHTTP.constants).each do |constant|
|
37
|
+
OriginalNetHTTP.send(:const_set, constant, @webMockNetHTTP.const_get(constant))
|
38
|
+
end
|
31
39
|
end
|
32
40
|
|
33
41
|
@webMockNetHTTP = Class.new(Net::HTTP) do
|
data/lib/webmock/version.rb
CHANGED
@@ -13,6 +13,39 @@ unless RUBY_PLATFORM =~ /java/
|
|
13
13
|
|
14
14
|
#functionality only supported for em-http-request 1.x
|
15
15
|
if defined?(EventMachine::HttpConnection)
|
16
|
+
context 'when a real request is made and redirects are followed' do
|
17
|
+
before { WebMock.allow_net_connect! }
|
18
|
+
|
19
|
+
# This url redirects to the https URL.
|
20
|
+
let(:http_url) { "http://raw.github.com:80/gist/fb555cb593f3349d53af/6921dd638337d3f6a51b0e02e7f30e3c414f70d6/vcr_gist" }
|
21
|
+
let(:https_url) { http_url.gsub('http', 'https').gsub('80', '443') }
|
22
|
+
|
23
|
+
def make_request
|
24
|
+
EM.run do
|
25
|
+
request = EM::HttpRequest.new(http_url).get(:redirects => 1)
|
26
|
+
request.callback { EM.stop }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "invokes the globally_stub_request hook with both requests" do
|
31
|
+
urls = []
|
32
|
+
WebMock.globally_stub_request { |r| urls << r.uri.to_s; nil }
|
33
|
+
|
34
|
+
make_request
|
35
|
+
|
36
|
+
urls.should eq([http_url, https_url])
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'invokes the after_request hook with both requests' do
|
40
|
+
urls = []
|
41
|
+
WebMock.after_request { |req, res| urls << req.uri.to_s }
|
42
|
+
|
43
|
+
make_request
|
44
|
+
|
45
|
+
urls.should eq([http_url, https_url])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
16
49
|
describe "with middleware" do
|
17
50
|
|
18
51
|
it "should work with request middleware" do
|
@@ -38,19 +71,21 @@ unless RUBY_PLATFORM =~ /java/
|
|
38
71
|
end
|
39
72
|
end
|
40
73
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
middleware = Class.new do
|
74
|
+
let(:response_middleware) do
|
75
|
+
Class.new do
|
45
76
|
def response(resp)
|
46
77
|
resp.response = 'bar'
|
47
78
|
end
|
48
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should work with response middleware" do
|
83
|
+
stub_request(:get, "www.example.com").to_return(:body => 'foo')
|
49
84
|
|
50
85
|
EM.run do
|
51
86
|
conn = EventMachine::HttpRequest.new('http://www.example.com/')
|
52
87
|
|
53
|
-
conn.use
|
88
|
+
conn.use response_middleware
|
54
89
|
|
55
90
|
http = conn.get
|
56
91
|
|
@@ -60,6 +95,36 @@ unless RUBY_PLATFORM =~ /java/
|
|
60
95
|
end
|
61
96
|
end
|
62
97
|
end
|
98
|
+
|
99
|
+
let(:webmock_server_url) { "http://#{WebMockServer.instance.host_with_port}/" }
|
100
|
+
|
101
|
+
shared_examples_for "em-http-request middleware/after_request hook integration" do
|
102
|
+
it 'yields the original raw body to the after_request hook even if a response middleware modifies the body' do
|
103
|
+
yielded_response_body = nil
|
104
|
+
::WebMock.after_request do |request, response|
|
105
|
+
yielded_response_body = response.body
|
106
|
+
end
|
107
|
+
|
108
|
+
EM::HttpRequest.use response_middleware
|
109
|
+
|
110
|
+
EM.run do
|
111
|
+
http = EventMachine::HttpRequest.new(webmock_server_url).get
|
112
|
+
http.callback { EM.stop }
|
113
|
+
end
|
114
|
+
|
115
|
+
yielded_response_body.should eq("hello world")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'making a real request' do
|
120
|
+
before { WebMock.allow_net_connect! }
|
121
|
+
include_examples "em-http-request middleware/after_request hook integration"
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when the request is stubbed' do
|
125
|
+
before { stub_request(:get, webmock_server_url).to_return(:body => 'hello world') }
|
126
|
+
include_examples "em-http-request middleware/after_request hook integration"
|
127
|
+
end
|
63
128
|
end
|
64
129
|
|
65
130
|
# not pretty, but it works
|
@@ -174,7 +239,8 @@ unless RUBY_PLATFORM =~ /java/
|
|
174
239
|
|
175
240
|
it "#request_signature doesn't mutate the original uri" do
|
176
241
|
subject.uri.should == Addressable::URI.parse("http://www.example.com/?a=1")
|
177
|
-
|
242
|
+
signature = WebMock::RequestRegistry.instance.requested_signatures.hash.keys.first
|
243
|
+
signature.uri.should == Addressable::URI.parse(uri)
|
178
244
|
end
|
179
245
|
end
|
180
246
|
end
|
@@ -86,6 +86,19 @@ describe "Net:HTTP" do
|
|
86
86
|
Object.const_get("Net").const_get("HTTP").constants(false).map(&:to_s).should include("Get")
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
describe "after WebMock is disabled" do
|
91
|
+
after(:each) do
|
92
|
+
WebMock.enable!
|
93
|
+
end
|
94
|
+
it "Net::HTTP should have the same constants" do
|
95
|
+
orig_consts_number = Net::HTTP.constants.size
|
96
|
+
Net::HTTP.send(:const_set, "TEST_CONST", 10)
|
97
|
+
Net::HTTP.constants.size.should == orig_consts_number + 1
|
98
|
+
WebMock.disable!
|
99
|
+
Net::HTTP.constants.size.should == orig_consts_number + 1
|
100
|
+
end
|
101
|
+
end
|
89
102
|
end
|
90
103
|
|
91
104
|
it "should work with block provided" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 35
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 1.8.
|
9
|
+
- 10
|
10
|
+
version: 1.8.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bartosz Blimke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-09-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: addressable
|