Skip to content
Browse files

Raise an error if a response is recorded with an invalid body.

This can occur when a non-standard Faraday stack is used, where a response-modifying middleware comes after the HTTP adapter.

For #159.
  • Loading branch information...
1 parent e536a51 commit d924f660fe198605ccf4de93f337f490a33a8131 @myronmarston committed
Showing with 11 additions and 0 deletions.
  1. +5 −0 lib/vcr/structs.rb
  2. +6 −0 spec/vcr/structs_spec.rb
5 lib/vcr/structs.rb
@@ -60,6 +60,11 @@ def try_encode_string(string, encoding)
def initialize(*args)
+ if body && !body.is_a?(String)
+ raise ArgumentError, "#{self.class} initialized with an invalid body: #{body.inspect}."
+ end
# Ensure that the body is a raw string, in case the string instance
# has been subclassed or extended with additional instance variables
# or attributes, so that it is serialized to YAML as a raw string.
6 spec/vcr/structs_spec.rb
@@ -49,6 +49,12 @@
it 'converts nil to a blank string' do
instance(nil).body.should eq("")
+ it 'raises an error if given another type of object as the body' do
+ expect {
+ instance(:a => "hash")
+ }.to raise_error(ArgumentError)
+ end
module VCR

0 comments on commit d924f66

Please sign in to comment.
Something went wrong with that request. Please try again.