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
  • 16 commits
  • 22 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 02, 2011
@myronmarston Fix readme links. bd013c9
@myronmarston Fixes for relish. 5bd3bff
@myronmarston Use "And" instead of second "Given". b19a93f
@myronmarston Fleshed out cassette format outline. fb6dbaa
Commits on Mar 05, 2011
@myronmarston Fix faraday middleware to handle nil response headers. 0131853
Commits on Mar 06, 2011
@myronmarston Fixed net/http adapter.
URI#request_uri should be used rather than URI#path, since #request_uri includes query params but #path does not.
534925a
@myronmarston Fix faraday adapter so that it properly normalizes query parameters. 0d4d9f5
@myronmarston Fix broken cukes.
We can't have different adapters return different values for #normalize_uri because it breaks when you stub with multiple libraries.
70b195f
Commits on Mar 19, 2011
@myronmarston 1.7.1 release. 0022cf7
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
2  .gitignore
@@ -30,4 +30,4 @@ Gemfile.lock
features/README.md
features/CHANGELOG.md
-features/LICENSE
+features/LICENSE.md
View
3  .travis.yml
@@ -1 +1,4 @@
script: "rake ci:build"
+rvm:
+ - 1.8.7
+ - 1.9.2
View
27 CHANGELOG.md
@@ -1,8 +1,29 @@
-# Changelog
-
## In git
-[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.0...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)
+
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.0...v1.7.1)
+
+* Fix Faraday adapter so that it properly normalizes query parameters
+ in the same way that Faraday itself does.
## 1.7.0 (March 1, 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
10 README.md
@@ -32,17 +32,17 @@ maintenance) and accurate (the response from example.com will contain the same h
* Automatically records and replays your HTTP interactions with minimal setup/configuration code.
* Supports and works with the HTTP stubbing facilities of multiple libraries. Currently, the
following are supported:
- * FakeWeb
- * WebMock
- * Typhoeus
- * Faraday
+ * [FakeWeb](https://github.com/chrisk/fakeweb)
+ * [WebMock](https://github.com/bblimke/webmock)
+ * [Typhoeus](https://github.com/dbalatero/typhoeus)
+ * [Faraday](https://github.com/technoweenie/faraday)
* Supports multiple HTTP libraries:
* [Patron](http://github.com/toland/patron) (when using WebMock)
* [Curb](http://github.com/taf2/curb) (when using WebMock -- only supports Curb::Easy at the moment)
* [HTTPClient](http://github.com/nahi/httpclient) (when using WebMock)
* [em-http-request](http://github.com/igrigorik/em-http-request) (when using WebMock)
* [Net::HTTP](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html) (when using FakeWeb and WebMock)
- * [Typhoeus](https://github.com/pauldix/typhoeus) (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
+ * [Typhoeus](https://github.com/dbalatero/typhoeus) (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
* [Faraday](https://github.com/technoweenie/faraday)
* And of course any library built on Net::HTTP, such as [Mechanize](http://github.com/tenderlove/mechanize),
[HTTParty](http://github.com/jnunemaker/httparty) or [Rest Client](http://github.com/archiloque/rest-client).
View
4 Rakefile
@@ -47,7 +47,9 @@ namespace :ci do
end
def ensure_relish_doc_symlinked(filename)
- from = File.expand_path("../features/#{filename}", __FILE__)
+ from_filename = filename.dup
+ from_filename << '.md' unless filename =~ /\.md$/
+ from = File.expand_path("../features/#{from_filename}", __FILE__)
to = File.expand_path("../#{filename}", __FILE__)
if File.symlink?(from)
View
8 features/.nav
@@ -1,7 +1,7 @@
-getting_started.md (Getting Started)
-CHANGELOG.md (Changelog)
-about_the_cucumber_features.md (About the Cucumber Features)
-LICENSE (License)
+- getting_started.md (Getting Started)
+- CHANGELOG.md (Changelog)
+- about_these_examples.md (About These Examples)
+- LICENSE.md (License)
- cassettes:
- format.feature
- no_cassette.feature
View
2  features/about_the_cucumber_features.md → features/about_these_examples.md
@@ -1,5 +1,3 @@
-## About the Cucumber Features
-
The cucumber features provided here demonstrate all of the major features of
VCR. These features are executable documentation for VCR.
View
14 features/cassettes/format.feature
@@ -5,8 +5,18 @@ Feature: Cassette format
human-readable/editable format. A cassette contains an array
of HTTP interactions, each of which has the following:
- - Request method, uri, body, headers
- - Response status (code & message), headers, body, http version
+ - request
+ - method
+ - uri
+ - body
+ - headers
+ - response
+ - status
+ - code
+ - message
+ - headers
+ - body
+ - http version
Scenario Outline: Request/Response data is saved to disk as YAML
Given a file named "cassette_format.rb" with:
View
2  features/cassettes/update_content_length_header.feature
@@ -40,7 +40,7 @@ Feature: Update content_length header
body: Hello <modified>
http_version: "1.1"
"""
- Given a file named "common_stuff.rb" with:
+ And a file named "common_stuff.rb" with:
"""
require 'vcr'
View
2  features/configuration/allow_http_connections_when_no_cassette.feature
@@ -1,4 +1,4 @@
-Feature: allow_http_connections_when_no_cassette
+Feature: Allow HTTP connections when no cassette
Usually, HTTP requests made when no cassette is inserted will result
in an error (see cassettes/no_cassette.feature). You can set the
View
2  features/getting_started.md
@@ -1,5 +1,3 @@
-## Getting Started
-
### Install it
[sudo] gem install vcr
View
16 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
@@ -26,7 +26,8 @@ def uri_should_be_ignored?(uri)
def stub_requests(http_interactions, match_attributes)
grouped_responses(http_interactions, match_attributes).each do |request_matcher, responses|
- queue = stub_queues[request_matcher]
+ matcher = request_matcher_with_normalized_uri(request_matcher)
+ queue = stub_queues[matcher]
responses.each { |res| queue << res }
end
end
@@ -82,6 +83,15 @@ def stub_queue_dup
def hash_of_arrays
Hash.new { |h, k| h[k] = [] }
end
+
+ def request_matcher_with_normalized_uri(matcher)
+ return matcher unless matcher.uri.is_a?(String) && matcher.uri.include?('+')
+
+ request = matcher.request.dup
+ request.uri = request.uri.gsub('+', '%20')
+
+ RequestMatcher.new(request, matcher.match_attributes)
+ end
end
end
end
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.0'
+ string = '1.8.0'
def string.parts
split('.').map { |p| p.to_i }
View
5 spec/support/http_library_adapters.rb
@@ -11,7 +11,7 @@ def get_header(header_key, response)
def make_http_request(method, url, body = nil, headers = {})
uri = URI.parse(url)
- Net::HTTP.new(uri.host, uri.port).send_request(method.to_s.upcase, uri.path, body, headers)
+ Net::HTTP.new(uri.host, uri.port).send_request(method.to_s.upcase, uri.request_uri, body, headers)
end
end
@@ -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
76 spec/support/shared_example_groups/http_library.rb
@@ -1,3 +1,5 @@
+require 'cgi'
+
NET_CONNECT_NOT_ALLOWED_ERROR = /You can use VCR to automatically record this request and replay it later/
shared_examples_for "an http library" do |library, supported_request_match_attributes, *other|
@@ -12,7 +14,79 @@
# so this gives us another alias we can use for the original method.
alias make_request make_http_request
- describe '#stub_requests using specific match_attributes' do
+ 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) }
+ let(:response_body) { "The response body" }
+ let(:match_requests_on) { [:method, :uri] }
+ let(:record_mode) { :none }
+
+ before(:each) do
+ subject.stub_requests([interaction], match_requests_on)
+ end
+
+ context "when the the stubbed request and response has no headers" do
+ let(:request) { VCR::Request.new(:get, 'http://example.com:80/') }
+ let(:response) { VCR::Response.new(status, nil, response_body, '1.1') }
+
+ it 'returns the response for a matching request' do
+ get_body_string(make_http_request(:get, 'http://example.com/')).should == response_body
+ end
+ end
+
+ def self.test_url(description, url)
+ context "when a URL #{description} has been stubbed" do
+ let(:request) { VCR::Request.new(:get, url) }
+ let(:response) { VCR::Response.new(status, nil, response_body, '1.1') }
+
+ it 'returns the expected response for the same request' do
+ get_body_string(make_http_request(:get, url)).should == response_body
+ end
+ end
+ end
+
+ test_url "that has query params", "http://example.com/search?q=param"
+ test_url "with spaces encoded as +", "http://example.com/search?q=a+b"
+ test_url "with spaces encoded as %20", "http://example.com/search?q=a%20b"
+ test_url "with an encoded ampersand", "http://example.com:80/search?q=#{CGI.escape("Q&A")}"
+ test_url "with a complex escaped query param", "http://example.com:80/search?q=#{CGI.escape("A&(! 234k !@ kasdj232\#$ kjw35")}"
+ end
+
+ describe '.stub_requests using specific match_attributes' do
before(:each) { subject.http_connections_allowed = false }
let(:interactions) { VCR::YAML.load_file(File.join(VCR::SPEC_ROOT, 'fixtures', YAML_SERIALIZATION_VERSION, 'match_requests_on.yml')) }
View
13 spec/support/shared_example_groups/http_stubbing_adapter.rb
@@ -43,19 +43,6 @@ def adapter_enabled?(adapter)
end
end
- describe '.stub_requests' do
- let(:request) { VCR::Request.new(:get, 'http://example.com/') }
- let(:status) { VCR::ResponseStatus.new(200, 'OK') }
- let(:response) { VCR::Response.new(status) }
- let(:interaction) { VCR::HTTPInteraction.new(request, response) }
-
- it 'works when the request and response has no headers' do
- expect {
- subject.stub_requests([interaction], [:method, :uri])
- }.not_to raise_error
- end
- end
-
if other.include?(:needs_net_http_extension)
describe '.request_uri' do
it 'returns the uri for the given http request' do
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.