Skip to content

Commit 5a13948

Browse files
authored
Do not raise an exception if the body is missing from the response (#1044)
1 parent 747e792 commit 5a13948

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/vcr/structs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def force_encode_string(string, encoding)
3131
end
3232

3333
def try_encode_string(string, encoding_name)
34-
return string if encoding_name.nil?
34+
return string if encoding_name.nil? || string.nil?
3535

3636
encoding = Encoding.find(encoding_name)
3737
return string if string.encoding == encoding

spec/lib/vcr/structs_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ def body_hash(key, value)
149149
expect(i.response).to eq(Response.new(ResponseStatus.new))
150150
end
151151

152+
it 'uses a blank body if it is missing from the response' do
153+
hash['response']['body'] = { 'encoding' => 'US-ASCII' }
154+
155+
i = HTTPInteraction.from_hash(hash)
156+
expect(i.response.body).to eq('')
157+
end
158+
152159
it 'decodes the base64 body string' do
153160
hash['request']['body'] = body_hash('base64_string', Base64.encode64('req body'))
154161
hash['response']['body'] = body_hash('base64_string', Base64.encode64('res body'))

0 commit comments

Comments
 (0)