Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add spec for consistent handling of empty body responses.

The fix for this is dependent upon pull requests I've opened
with FakeWeb, WebMock and Faraday:

- chrisk/fakeweb#32
- bblimke/webmock#190
- https://github.com/technoweenie/faraday/pull/168

Closes #173.
  • Loading branch information...
commit b5b13502dfff23512a22848c798199755e9320b0 1 parent 26a544a
@myronmarston authored
View
11 spec/support/http_library_adapters.rb
@@ -16,6 +16,7 @@ def downcase_headers(headers)
def self.http_library_name; 'Net::HTTP'; end
def get_body_string(response); response.body; end
+ alias get_body_object get_body_string
def get_header(header_key, response)
response.get_fields(header_key)
@@ -46,6 +47,7 @@ def normalize_request_headers(headers)
def self.http_library_name; 'Patron'; end
def get_body_string(response); response.body; end
+ alias get_body_object get_body_string
def get_header(header_key, response)
response.headers[header_key]
@@ -69,6 +71,10 @@ def get_body_string(response)
string.respond_to?(:read) ? string.read : string
end
+ def get_body_object(response)
+ response.body
+ end
+
def get_header(header_key, response)
response.header[header_key]
end
@@ -88,6 +94,7 @@ def self.http_library_name; 'EM HTTP Request'; end
def get_body_string(response)
response.response
end
+ alias get_body_object get_body_string
def get_header(header_key, response)
values = response.response_header[header_key.upcase.gsub('-', '_')]
@@ -114,6 +121,7 @@ def self.http_library_name; "Curb"; end
def get_body_string(response)
response.body_str
end
+ alias get_body_object get_body_string
def get_header(header_key, response)
headers = response.header_str.split("\r\n")[1..-1]
@@ -149,6 +157,7 @@ def self.http_library_name; "Typhoeus"; end
def get_body_string(response)
response.body
end
+ alias get_body_object get_body_string
def get_header(header_key, response)
response.headers_hash[header_key]
@@ -169,6 +178,7 @@ def self.http_library_name; "Excon"; end
def get_body_string(response)
response.body
end
+ alias get_body_object get_body_string
def get_header(header_key, response)
response.headers[header_key]
@@ -198,6 +208,7 @@ class << self; self; end.class_eval do
def get_body_string(response)
response.body
end
+ alias get_body_object get_body_string
def get_header(header_key, response)
value = response.headers[header_key]
View
14 spec/support/shared_example_groups/hook_into_http_library.rb
@@ -55,6 +55,20 @@ def self.test_record_and_playback(description, query)
test_record_and_playback "with spaces encoded as %20", "q=a%20b"
test_record_and_playback "with a complex escaped query param", "q=#{CGI.escape("A&(! 234k !@ kasdj232\#$ kjw35")}"
+ it 'plays back an empty body response exactly as it was recorded (e.g. nil vs empty string)' do
+ pending "awaiting an external fix", :if => library.gsub('_', '/').include?('net/http') do
+ get_body = lambda do
+ VCR.use_cassette('empty_body', :record => :once) do
+ get_body_object make_http_request(:get, "http://localhost:#{VCR::SinatraApp.port}/204")
+ end
+ end
+
+ recorded = get_body.call
+ played_back = get_body.call
+ played_back.should eq(recorded)
+ end
+ end
+
describe 'making an HTTP request' do
let(:status) { VCR::ResponseStatus.new(200, 'OK') }
let(:interaction) { VCR::HTTPInteraction.new(request, response) }
View
4 spec/support/sinatra_app.rb
@@ -34,6 +34,10 @@ class SinatraApp < ::Sinatra::Base
'header set'
end
+ get '/204' do
+ status 204
+ end
+
# we use a global counter so that every response is different;
# this ensures that the test demonstrates that the response
# is being played back (and not running a 2nd real request)
Please sign in to comment.
Something went wrong with that request. Please try again.