Navigation Menu

Skip to content

Commit

Permalink
Raise an error if a response is recorded with an invalid body.
Browse files Browse the repository at this point in the history
This can occur when a non-standard Faraday stack is used, where a response-modifying middleware comes after the HTTP adapter.

For vcr#159.
  • Loading branch information
myronmarston committed May 7, 2012
1 parent e536a51 commit d924f66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/vcr/structs.rb
Expand Up @@ -60,6 +60,11 @@ def try_encode_string(string, encoding)

def initialize(*args)
super

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.
Expand Down
6 changes: 6 additions & 0 deletions spec/vcr/structs_spec.rb
Expand Up @@ -49,6 +49,12 @@
it 'converts nil to a blank string' do
instance(nil).body.should eq("")
end

it 'raises an error if given another type of object as the body' do
expect {
instance(:a => "hash")
}.to raise_error(ArgumentError)
end
end

module VCR
Expand Down

0 comments on commit d924f66

Please sign in to comment.