spec/vcr/structs/response_spec.rb in vcr-1.6.0 vs spec/vcr/structs/response_spec.rb in vcr-1.7.0

- old
+ new

@@ -1,10 +1,10 @@ require 'spec_helper' describe VCR::Response do describe '.from_net_http_response' do - let(:response) { YAML.load(File.read("#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/example_net_http_response.yml")) } + let(:response) { VCR::YAML.load_file("#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/example_net_http_response.yml") } subject { described_class.from_net_http_response(response) } it { should be_instance_of(described_class) } its(:body) { should == 'The response from example.com' } its(:http_version) { should == '1.1' } @@ -32,8 +32,30 @@ end it_performs 'body normalization' do def instance(body) described_class.new(:status, {}, body, '1.1') + end + end + + describe '#update_content_length_header' do + def instance(body, content_length = nil) + headers = { 'content-type' => 'text' } + headers.merge!('content-length' => content_length) if content_length + described_class.new(VCR::ResponseStatus.new, headers, body) + end + + it 'does nothing when the response lacks a content_length header' do + inst = instance('the body') + expect { + inst.update_content_length_header + }.not_to change { inst.headers['content-length'] } + end + + it 'sets the content_length header to the response body length when the header is present' do + inst = instance('the body', '3') + expect { + inst.update_content_length_header + }.to change { inst.headers['content-length'] }.from(['3']).to(['8']) end end end