Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 16 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
View
2  .gitignore
@@ -30,4 +30,4 @@ Gemfile.lock
features/README.md
features/CHANGELOG.md
-features/LICENSE
+features/LICENSE.md
View
11 CHANGELOG.md
@@ -1,8 +1,13 @@
-# Changelog
-
## In git
-[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.0...master)
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.7.1...master)
+
+## 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
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
12 lib/vcr/http_stubbing_adapters/faraday.rb
@@ -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
2  lib/vcr/middleware/faraday.rb
@@ -18,7 +18,7 @@ def 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),
+ :response_headers => correctly_cased_headers(response.headers || {}),
:body => response.body
)
View
2  lib/vcr/version.rb
@@ -3,7 +3,7 @@ module VCR
def version
@version ||= begin
- string = '1.7.0'
+ string = '1.7.1'
def string.parts
split('.').map { |p| p.to_i }
View
2  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
View
50 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,53 @@
# 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
+ 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') }
+
+ 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
+ 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

No commit comments for this range

Something went wrong with that request. Please try again.