Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: myronmarston/vcr
...
head fork: myronmarston/vcr
  • 7 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 24, 2011
@myronmarston Add rvm rubies to travis build. e875ddc
Commits on Mar 26, 2011
@myronmarston Don't build so many rubies. Travis seems to have gotten confused. f189e62
@myronmarston Ensure that header values are the same when recording and replaying.
- Typhoeus would have a single header value like 'text/html' when recording, but it was in an array on playback ['text/html'].
- Faraday headers are returned with lower case keys, and I was not handling this properly at all.

There are a few adapter/http library combinations that do not work properly when there are multiple values for one header:
- Faraday/Patron
- WebMock/HTTP Client
- WebMock/EM HTTP Request
- WebMock/Curb

I think this is due to a bug in those libraries.  I could change the way I pass headers to Faraday and WebMock, but that would break the other libs used with Faraday and WebMock (i.e. Faraday/Net::HTTP or WebMock/Net::HTTP) so I think it's best for now to just leave these pending.

Closes #50.
dbbc4b3
@myronmarston Update to em-http-request 0.3.0.
This fixes some specs that were previously pending due to a bug in em-http-request.
cc7f1b5
@myronmarston 1.7.2 release. 717d7c8
Commits on Apr 01, 2011
@myronmarston Update to Faraday 0.6. fb156a7
@myronmarston 1.8.0 release. 487332d
View
3  .travis.yml
@@ -1 +1,4 @@
script: "rake ci:build"
+rvm:
+ - 1.8.7
+ - 1.9.2
View
18 CHANGELOG.md
@@ -1,6 +1,22 @@
## In git
-[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.1...master)
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.8.0...master)
+
+## 1.8.0 (March 31, 2011)
+
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.2...v1.8.0)
+
+* Updated Faraday middleware to work with newly released Faraday 0.6.0.
+
+## 1.7.2 (March 26, 2011)
+
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.1...v1.7.2)
+
+* Fixed Typhoeus adapter so headers are returned in the same form during
+ playback as they would be without VCR. Bug reported by
+ [Avdi Grimm](https://github.com/avdi).
+* Fixed Faraday adapter so it treats response headers in the same way
+ Faraday itself does (i.e. with lowercase keys).
## 1.7.1 (March 19, 2011)
View
2  Gemfile
@@ -5,7 +5,7 @@ group :development do
# patron and em-http-request can't install on JRuby, so we have to limit their platform here.
platforms :ruby do
gem 'patron', '0.4.9'
- gem 'em-http-request', '~> 0.2.7'
+ gem 'em-http-request', '~> 0.3.0'
gem 'curb', '0.7.8'
gem 'typhoeus', '~> 0.2.1'
end
View
4 lib/vcr/http_stubbing_adapters/faraday.rb
@@ -6,8 +6,8 @@ module Faraday
include Common
extend self
- MINIMUM_VERSION = '0.5.3'
- MAXIMUM_VERSION = '0.5'
+ MINIMUM_VERSION = '0.6.0'
+ MAXIMUM_VERSION = '0.6'
attr_writer :http_connections_allowed
View
12 lib/vcr/http_stubbing_adapters/typhoeus.rb
@@ -32,7 +32,7 @@ def stub_requests(http_interactions, match_attributes)
::Typhoeus::Response.new(
:code => response.status.code,
:body => response.body,
- :headers_hash => response.headers
+ :headers_hash => normalized_response_headers(response)
)
end
)
@@ -65,6 +65,16 @@ def request_hash(request_matcher)
hash
end
+
+ def normalized_response_headers(response)
+ hash = {}
+
+ response.headers.each do |key, values|
+ hash[key] = values.size == 1 ? values.first : values
+ end if response.headers
+
+ hash
+ end
end
end
end
View
23 lib/vcr/middleware/faraday.rb
@@ -16,13 +16,13 @@ def call(env)
if VCR::HttpStubbingAdapters::Faraday.uri_should_be_ignored?(request.uri)
@app.call(env)
elsif response = VCR::HttpStubbingAdapters::Faraday.stubbed_response_for(request_matcher)
- env.update(
- :status => response.status.code,
- :response_headers => correctly_cased_headers(response.headers || {}),
- :body => response.body
- )
+ headers = env[:response_headers] ||= ::Faraday::Utils::Headers.new
+ headers.update response.headers if response.headers
+ env.update :status => response.status.code, :body => response.body
- env[:response].finish(env)
+ faraday_response = ::Faraday::Response.new
+ faraday_response.finish(env) unless env[:parallel_manager]
+ env[:response] = faraday_response
elsif VCR::HttpStubbingAdapters::Faraday.http_connections_allowed?
response = @app.call(env)
@@ -63,17 +63,6 @@ def response_for(env)
'1.1'
)
end
-
- def correctly_cased_headers(headers)
- correctly_cased_hash = {}
-
- headers.each do |key, value|
- key = key.to_s.split('-').map { |segment| segment.capitalize }.join("-")
- correctly_cased_hash[key] = value
- end
-
- correctly_cased_hash
- end
end
end
end
View
2  lib/vcr/version.rb
@@ -3,7 +3,7 @@ module VCR
def version
@version ||= begin
- string = '1.7.1'
+ string = '1.8.0'
def string.parts
split('.').map { |p| p.to_i }
View
3  spec/support/http_library_adapters.rb
@@ -127,7 +127,8 @@ def get_body_string(response)
end
def get_header(header_key, response)
- response.headers[header_key]
+ value = response.headers[header_key]
+ value.split(', ') if value
end
def make_http_request(method, url, body = nil, headers = {})
View
44 spec/support/shared_example_groups/http_library.rb
@@ -14,6 +14,40 @@
# so this gives us another alias we can use for the original method.
alias make_request make_http_request
+ 1.upto(2) do |header_count|
+ describe "making an HTTP request that responds with #{header_count} Set-Cookie header(s)" do
+ define_method :get_set_cookie_header do
+ VCR.use_cassette('header_test', :record => :once) do
+ get_header 'Set-Cookie', make_http_request(:get, "http://localhost:#{VCR::SinatraApp.port}/set-cookie-headers/#{header_count}")
+ end
+ end
+
+ define_method :should_be_pending do
+ if header_count == 2
+ [
+ 'HTTP Client',
+ 'EM HTTP Request',
+ 'Curb'
+ ].include?(adapter_module.http_library_name)
+ end
+ end
+
+ it 'returns the same header value when recording and replaying' do
+ pending "There appears to be a bug in the the HTTP stubbing library", :if => should_be_pending do
+ (recorded_val = get_set_cookie_header).should_not be_nil
+ replayed_val = get_set_cookie_header
+
+ # we don't care about order differences if the values are arrays
+ if recorded_val.is_a?(Array) && replayed_val.is_a?(Array)
+ replayed_val.should =~ recorded_val
+ else
+ replayed_val.should == recorded_val
+ end
+ end
+ end
+ end
+ end
+
describe 'making an HTTP request' do
let(:status) { VCR::ResponseStatus.new(200, 'OK') }
let(:interaction) { VCR::HTTPInteraction.new(request, response) }
@@ -39,16 +73,8 @@ def self.test_url(description, url)
let(:request) { VCR::Request.new(:get, url) }
let(:response) { VCR::Response.new(status, nil, response_body, '1.1') }
- def should_be_pending?
- return false unless described_class == VCR::HttpStubbingAdapters::WebMock
- return false unless request.uri.include?(CGI.escape('&'))
- self.class.included_modules.first.http_library_name == 'EM HTTP Request'
- end
-
it 'returns the expected response for the same request' do
- pending "WebMock/EM-HTTP bug", :if => should_be_pending? do
- get_body_string(make_http_request(:get, url)).should == response_body
- end
+ get_body_string(make_http_request(:get, url)).should == response_body
end
end
end
View
10 spec/support/sinatra_app.rb
@@ -14,6 +14,16 @@ class SinatraApp < ::Sinatra::Base
"FOO!"
end
+ get '/set-cookie-headers/1' do
+ headers 'Set-Cookie' => 'foo'
+ 'header set'
+ end
+
+ get '/set-cookie-headers/2' do
+ headers 'Set-Cookie' => %w[ foo bar ]
+ 'header set'
+ end
+
def self.port
server.port
end
View
6 spec/vcr/http_stubbing_adapters/faraday_spec.rb
@@ -7,9 +7,9 @@
:status_message_not_exposed, :does_not_support_rotating_responses
it_performs('version checking',
- :valid => %w[ 0.5.3 0.5.10 ],
- :too_low => %w[ 0.5.2 0.4.99 ],
- :too_high => %w[ 0.6.0 1.0.0 ]
+ :valid => %w[ 0.6.0 0.6.10 ],
+ :too_low => %w[ 0.5.9 0.4.99 ],
+ :too_high => %w[ 0.7.0 1.0.0 ]
) do
before(:each) { @orig_version = Faraday::VERSION }
after(:each) { Faraday::VERSION = @orig_version }
View
4 vcr.gemspec
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
'fakeweb' => '~> 1.3.0',
'webmock' => '~> 1.6.0',
- 'faraday' => '~> 0.5.3',
+ 'faraday' => '~> 0.6.0',
'httpclient' => '~> 2.1.5.2',
'timecop' => '~> 0.3.5',
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
{
'patron' => '0.4.9',
- 'em-http-request' => '~> 0.2.7',
+ 'em-http-request' => '~> 0.3.0',
'curb' => '0.7.8',
'typhoeus' => '~> 0.2.1'
}.each do |lib, version|

No commit comments for this range

Something went wrong with that request. Please try again.