webmock 1.8.7 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.8
4
+
5
+ * Fixed Net::HTTP adapter so that it returns `nil` for an empty body response.
6
+
7
+ Thanks to [Myron Marston](https://github.com/myronmarston)
8
+
9
+ * Gemspec defines compatibility with Addressable ~> 2.2.8, not >= 2.3.0
10
+
11
+ * Specs compatibility with Typhoeus 0.4.0
12
+
13
+ Thanks to [Hans Hasselberg](https://github.com/i0rek)
14
+
15
+ * Handling content types that specify a charset
16
+
17
+ Thanks to [Kevin Glowacz](https://github.com/kjg)
18
+
19
+ * Fixed em-http-request adapter to correctly fetch authorization header from a request
20
+
21
+ Thanks to [Julien Boyer](https://github.com/chatgris)
22
+
23
+ * Fixing travis-ci image to report master's status
24
+
25
+ Thanks to [Ryan Schlesinger](https://github.com/ryansch)
26
+
27
+ * Fixed problem with em-http-request callback triggering if there were other EM::Deferred callbacks registered
28
+
29
+ Thanks to [Jon Leighton](https://github.com/jonleighton)
30
+
31
+ * Fixed problem with em-http-request appending the query to the URI a second time, and
32
+ the parameters are repeated.
33
+
34
+ Thanks to [Jon Leighton](https://github.com/jonleighton)
35
+
3
36
  ## 1.8.7
4
37
 
5
38
  * Compatibility with RSpec >= 2.10
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- WebMock [![Build Status](https://secure.travis-ci.org/bblimke/webmock.png)](http://travis-ci.org/bblimke/webmock) [![Dependency Status](https://gemnasium.com/bblimke/webmock.png)](http://gemnasium.com/bblimke/webmock)
1
+ WebMock [![Build Status](https://secure.travis-ci.org/bblimke/webmock.png?branch=master)](http://travis-ci.org/bblimke/webmock) [![Dependency Status](https://gemnasium.com/bblimke/webmock.png)](http://gemnasium.com/bblimke/webmock)
2
2
  =======
3
3
 
4
4
  Library for stubbing and setting expectations on HTTP requests in Ruby.
@@ -707,6 +707,11 @@ People who submitted patches and new features or suggested improvements. Many th
707
707
  * Eric Oestrich
708
708
  * erwanlr
709
709
  * Ben Bleything
710
+ * Jon Leighton
711
+ * Ryan Schlesinger
712
+ * Julien Boyer
713
+ * Kevin Glowacz
714
+ * Hans Hasselberg
710
715
 
711
716
  For a full list of contributors you can visit the
712
717
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -105,16 +105,6 @@ if defined?(EventMachine::HttpClient)
105
105
  self
106
106
  elsif WebMock.net_connect_allowed?(request_signature.uri)
107
107
  send_request_without_webmock(head, body)
108
- callback {
109
- if WebMock::CallbackRegistry.any_callbacks?
110
- webmock_response = build_webmock_response
111
- WebMock::CallbackRegistry.invoke_callbacks(
112
- {:lib => :em_http_request, :real_request => true},
113
- request_signature,
114
- webmock_response)
115
- end
116
- }
117
- self
118
108
  else
119
109
  raise WebMock::NetConnectNotAllowedError.new(request_signature)
120
110
  end
@@ -123,6 +113,18 @@ if defined?(EventMachine::HttpClient)
123
113
  alias_method :send_request_without_webmock, :send_request
124
114
  alias_method :send_request, :send_request_with_webmock
125
115
 
116
+ def set_deferred_status(status, *args)
117
+ if status == :succeeded && !stubbed_webmock_response && WebMock::CallbackRegistry.any_callbacks?
118
+ webmock_response = build_webmock_response
119
+ WebMock::CallbackRegistry.invoke_callbacks(
120
+ {:lib => :em_http_request, :real_request => true},
121
+ request_signature,
122
+ webmock_response)
123
+ end
124
+
125
+ super
126
+ end
127
+
126
128
  def request_signature
127
129
  @request_signature ||= build_request_signature
128
130
  end
@@ -153,8 +155,8 @@ if defined?(EventMachine::HttpClient)
153
155
  end
154
156
 
155
157
  method = @req.method
156
- uri = @req.uri
157
- auth = @req.proxy[:authorization] if @req.proxy
158
+ uri = @req.uri.clone
159
+ auth = @req.headers[:'proxy-authorization']
158
160
  query = @req.query
159
161
 
160
162
  if auth
@@ -128,7 +128,10 @@ module WebMock
128
128
 
129
129
  def build_net_http_response(webmock_response, &block)
130
130
  response = Net::HTTPResponse.send(:response_class, webmock_response.status[0].to_s).new("1.0", webmock_response.status[0].to_s, webmock_response.status[1])
131
- response.instance_variable_set(:@body, webmock_response.body)
131
+ body = webmock_response.body
132
+ body = nil if body.to_s == ''
133
+
134
+ response.instance_variable_set(:@body, body)
132
135
  webmock_response.headers.to_a.each do |name, values|
133
136
  values = [values] unless values.is_a?(Array)
134
137
  values.each do |value|
@@ -27,6 +27,7 @@ module WebMock
27
27
 
28
28
  def matches?(request_signature)
29
29
  content_type = request_signature.headers['Content-Type'] if request_signature.headers
30
+ content_type = content_type.split(';').first if content_type
30
31
  @method_pattern.matches?(request_signature.method) &&
31
32
  @uri_pattern.matches?(request_signature.uri) &&
32
33
  (@body_pattern.nil? || @body_pattern.matches?(request_signature.body, content_type || "")) &&
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '1.8.7' unless defined?(::WebMock::VERSION)
2
+ VERSION = '1.8.8' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -141,26 +141,41 @@ unless RUBY_PLATFORM =~ /java/
141
141
  end
142
142
 
143
143
  describe "mocking EM::HttpClient API" do
144
+ let(:uri) { "http://www.example.com/" }
145
+
144
146
  before do
145
- stub_request(:get, "www.example.com/")
147
+ stub_request(:get, uri)
146
148
  WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable!
147
149
  end
148
- subject do
150
+
151
+ def client(uri, options = {})
149
152
  client = nil
150
153
  EM.run do
151
- client = EventMachine::HttpRequest.new('http://www.example.com/').get
154
+ client = EventMachine::HttpRequest.new(uri).get(options)
152
155
  client.callback { EM.stop }
153
156
  client.errback { failed }
154
157
  end
155
158
  client
156
159
  end
157
160
 
161
+ subject { client(uri) }
162
+
158
163
  it 'should support #uri' do
159
- subject.uri.should == Addressable::URI.parse('http://www.example.com/')
164
+ subject.uri.should == Addressable::URI.parse(uri)
160
165
  end
161
166
 
162
167
  it 'should support #last_effective_url' do
163
- subject.last_effective_url.should == Addressable::URI.parse('http://www.example.com/')
168
+ subject.last_effective_url.should == Addressable::URI.parse(uri)
169
+ end
170
+
171
+ context "with a query" do
172
+ let(:uri) { "http://www.example.com/?a=1&b=2" }
173
+ subject { client("http://www.example.com/?a=1", :query => { 'b' => 2 }) }
174
+
175
+ it "#request_signature doesn't mutate the original uri" do
176
+ subject.uri.should == Addressable::URI.parse("http://www.example.com/?a=1")
177
+ subject.request_signature.uri.should == Addressable::URI.parse(uri)
178
+ end
164
179
  end
165
180
  end
166
181
 
@@ -49,7 +49,7 @@ module EMHttpRequestSpecHelper
49
49
  end
50
50
 
51
51
  def connection_refused_exception_class
52
- ""
52
+ RuntimeError
53
53
  end
54
54
 
55
55
  def http_library
@@ -17,5 +17,20 @@ shared_context "complex cross-concern behaviors" do |*adapter_info|
17
17
  played_back_response.headers.keys.should include('Set-Cookie')
18
18
  played_back_response.should == real_response
19
19
  end
20
+
21
+ let(:no_content_url) { 'http://httpstat.us/204' }
22
+ [nil, ''].each do |stub_val|
23
+ it "returns the same value (nil or "") for a request stubbed as #{stub_val.inspect} that a real empty response has" do
24
+ unless http_library == :curb
25
+ WebMock.allow_net_connect!
26
+
27
+ real_response = http_request(:get, no_content_url)
28
+ stub_request(:get, no_content_url).to_return(:status => 204, :body => stub_val)
29
+ stubbed_response = http_request(:get, no_content_url)
30
+
31
+ stubbed_response.body.should eq(real_response.body)
32
+ end
33
+ end
34
+ end
20
35
  end
21
36
 
@@ -190,10 +190,10 @@ shared_context "request expectations" do |*adapter_info|
190
190
 
191
191
  it "should fail if request was executed with different body" do
192
192
  lambda {
193
- http_request(:get, "http://www.example.com/", :body => "abc")
194
- a_request(:get, "www.example.com").
193
+ http_request(:post, "http://www.example.com/", :body => "abc")
194
+ a_request(:post, "www.example.com").
195
195
  with(:body => "def").should have_been_made
196
- }.should fail_with(%r(The request GET http://www.example.com/ with body "def" was expected to execute 1 time but it executed 0 times))
196
+ }.should fail_with(%r(The request POST http://www.example.com/ with body "def" was expected to execute 1 time but it executed 0 times))
197
197
  end
198
198
 
199
199
  describe "when expected request body is declared as a regexp" do
@@ -206,10 +206,10 @@ shared_context "request expectations" do |*adapter_info|
206
206
 
207
207
  it "should fail if request was executed with body not matching regexp" do
208
208
  lambda {
209
- http_request(:get, "http://www.example.com/", :body => "abc")
210
- a_request(:get, "www.example.com").
209
+ http_request(:post, "http://www.example.com/", :body => "abc")
210
+ a_request(:post, "www.example.com").
211
211
  with(:body => /^xabc/).should have_been_made
212
- }.should fail_with(%r(The request GET http://www.example.com/ with body /\^xabc/ was expected to execute 1 time but it executed 0 times))
212
+ }.should fail_with(%r(The request POST http://www.example.com/ with body /\^xabc/ was expected to execute 1 time but it executed 0 times))
213
213
  end
214
214
 
215
215
  end
@@ -389,11 +389,11 @@ shared_context "request expectations" do |*adapter_info|
389
389
 
390
390
  it "should satisfy expectation if request was executed with body and headers but they were not specified in expectantion" do
391
391
  lambda {
392
- http_request(:get, "http://www.example.com/",
392
+ http_request(:post, "http://www.example.com/",
393
393
  :body => "abc",
394
394
  :headers => SAMPLE_HEADERS
395
395
  )
396
- a_request(:get, "www.example.com").should have_been_made
396
+ a_request(:post, "www.example.com").should have_been_made
397
397
  }.should_not raise_error
398
398
  end
399
399
 
@@ -358,6 +358,13 @@ describe WebMock::RequestPattern do
358
358
  should_not match(WebMock::RequestSignature.new(:post, "www.example.com",
359
359
  :headers => {:content_type => 'application/xml'}, :body => "foo bar"))
360
360
  end
361
+
362
+ it "matches when the content type include a charset" do
363
+ WebMock::RequestPattern.new(:post, 'www.example.com', :body => body_hash).
364
+ should match(WebMock::RequestSignature.new(:post, "www.example.com", :headers => {:content_type => 'application/xml;charset=UTF-8'},
365
+ :body => "<opt a=\"1\" b=\"five\">\n <c>\n <d>e</d>\n <d>f</d>\n </c>\n</opt>\n"))
366
+
367
+ end
361
368
  end
362
369
  end
363
370
 
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = 'webmock'
16
16
 
17
- s.add_dependency 'addressable', '>= 2.2.7'
17
+ s.add_dependency 'addressable', '~> 2.2.8'
18
18
  s.add_dependency 'crack', '>=0.1.7'
19
19
 
20
20
  s.add_development_dependency 'rspec', '~> 2.10'
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: 57
4
+ hash: 39
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 8
9
- - 7
10
- version: 1.8.7
9
+ - 8
10
+ version: 1.8.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bartosz Blimke
@@ -15,28 +15,27 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-12 00:00:00 Z
18
+ date: 2012-07-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: addressable
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
26
- - - ">="
25
+ - - ~>
27
26
  - !ruby/object:Gem::Version
28
- hash: 9
27
+ hash: 23
29
28
  segments:
30
29
  - 2
31
30
  - 2
32
- - 7
33
- version: 2.2.7
31
+ - 8
32
+ version: 2.2.8
34
33
  type: :runtime
35
- version_requirements: *id001
34
+ prerelease: false
35
+ requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: crack
38
- prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ">="
@@ -48,11 +47,11 @@ dependencies:
48
47
  - 7
49
48
  version: 0.1.7
50
49
  type: :runtime
51
- version_requirements: *id002
50
+ prerelease: false
51
+ requirement: *id002
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: rspec
54
- prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
55
  none: false
57
56
  requirements:
58
57
  - - ~>
@@ -63,11 +62,11 @@ dependencies:
63
62
  - 10
64
63
  version: "2.10"
65
64
  type: :development
66
- version_requirements: *id003
65
+ prerelease: false
66
+ requirement: *id003
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: httpclient
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
70
  none: false
72
71
  requirements:
73
72
  - - ">="
@@ -79,11 +78,11 @@ dependencies:
79
78
  - 4
80
79
  version: 2.2.4
81
80
  type: :development
82
- version_requirements: *id004
81
+ prerelease: false
82
+ requirement: *id004
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: patron
85
- prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
86
  none: false
88
87
  requirements:
89
88
  - - ">="
@@ -95,11 +94,11 @@ dependencies:
95
94
  - 18
96
95
  version: 0.4.18
97
96
  type: :development
98
- version_requirements: *id005
97
+ prerelease: false
98
+ requirement: *id005
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: em-http-request
101
- prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
102
  none: false
104
103
  requirements:
105
104
  - - ">="
@@ -111,11 +110,11 @@ dependencies:
111
110
  - 2
112
111
  version: 1.0.2
113
112
  type: :development
114
- version_requirements: *id006
113
+ prerelease: false
114
+ requirement: *id006
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: curb
117
- prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
119
118
  none: false
120
119
  requirements:
121
120
  - - ">="
@@ -127,11 +126,11 @@ dependencies:
127
126
  - 0
128
127
  version: 0.8.0
129
128
  type: :development
130
- version_requirements: *id007
129
+ prerelease: false
130
+ requirement: *id007
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: typhoeus
133
- prerelease: false
134
- requirement: &id008 !ruby/object:Gem::Requirement
133
+ version_requirements: &id008 !ruby/object:Gem::Requirement
135
134
  none: false
136
135
  requirements:
137
136
  - - ">="
@@ -143,11 +142,11 @@ dependencies:
143
142
  - 3
144
143
  version: 0.3.3
145
144
  type: :development
146
- version_requirements: *id008
145
+ prerelease: false
146
+ requirement: *id008
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: excon
149
- prerelease: false
150
- requirement: &id009 !ruby/object:Gem::Requirement
149
+ version_requirements: &id009 !ruby/object:Gem::Requirement
151
150
  none: false
152
151
  requirements:
153
152
  - - ">="
@@ -159,11 +158,11 @@ dependencies:
159
158
  - 0
160
159
  version: 0.11.0
161
160
  type: :development
162
- version_requirements: *id009
161
+ prerelease: false
162
+ requirement: *id009
163
163
  - !ruby/object:Gem::Dependency
164
164
  name: minitest
165
- prerelease: false
166
- requirement: &id010 !ruby/object:Gem::Requirement
165
+ version_requirements: &id010 !ruby/object:Gem::Requirement
167
166
  none: false
168
167
  requirements:
169
168
  - - ">="
@@ -175,11 +174,11 @@ dependencies:
175
174
  - 2
176
175
  version: 2.2.2
177
176
  type: :development
178
- version_requirements: *id010
177
+ prerelease: false
178
+ requirement: *id010
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: rdoc
181
- prerelease: false
182
- requirement: &id011 !ruby/object:Gem::Requirement
181
+ version_requirements: &id011 !ruby/object:Gem::Requirement
183
182
  none: false
184
183
  requirements:
185
184
  - - ">"
@@ -191,7 +190,8 @@ dependencies:
191
190
  - 0
192
191
  version: 3.5.0
193
192
  type: :development
194
- version_requirements: *id011
193
+ prerelease: false
194
+ requirement: *id011
195
195
  description: WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.
196
196
  email:
197
197
  - bartosz.blimke@gmail.com