Browse files

Handle 204 response from resource#delete

Net::HTTP returns a nil body when it receives a 204 response, which
caused the client to raise a method not found on nil for empty?.

FakeWeb doesn't allow nil response bodies, so we had to use more
intrusive stubbing. There is a pull request to fix this bug on FakeWeb
[chrisk/fakeweb#32], so this test should be
updated upon FakeWeb being updated.
  • Loading branch information...
1 parent 0537a15 commit 9f6fa2532ac5d4a222e993dd3a6928bb40c546f6 Alexander Murmann & Ryan Spore committed Jul 26, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/twilio-ruby/rest/client.rb
  2. +8 −0 spec/rest/client_spec.rb
2 lib/twilio-ruby/rest/client.rb
@@ -218,7 +218,7 @@ def connect_and_send(request) # :doc:
rescue Exception
if retries_left > 0 then retries_left -= 1; retry else raise end
- object = MultiJson.load response.body unless response.body.empty?
+ object = MultiJson.load response.body unless response.body.nil? || response.body.empty?
if response.kind_of? Net::HTTPClientError
raise object['message'], object['code']
8 spec/rest/client_spec.rb
@@ -7,6 +7,14 @@'/phone_number', twilio).delete
+ it 'should not raise an error if the response body is nil' do
+ response = double(:response, body: nil)
+ connection = double(:connection, request: response)
+ twilio ='someSid', 'someToken')
+ twilio.instance_variable_set(:@connection, connection)
+'/phone_number', twilio).delete
+ end
it 'should set up a new client instance with the given sid and token' do
twilio ='someSid', 'someToken')
twilio.account_sid.should == 'someSid'

0 comments on commit 9f6fa25

Please sign in to comment.