Skip to content

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.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 14 commits
  • 13 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 30, 2012
@mislav mislav allow bundler 1.1 0d3d605
@myronmarston Lock em-http-request to version that works with WebMock 1.8.2.
em-http-request 1.0.2, just released today, breaks WebMock's em-http-request adapter.  There's a pull request to get it fixed in WebMock[1], but for now it's simplest to lock to 1.0.1.

[1] bblimke/webmock#168
4ac5db2
@myronmarston Re-upgrade to rspec 2.9.0.rc2.
On 2.9, metadata filter lambdas are only invoked if the named key is present in the metadata hash, so the old way we made :skip_vcr_reset work is no longer supported.
4fbcc9b
@myronmarston Test against new webmock, excon and em-http-request releases. 73df359
@myronmarston Don't try to encode to a nil encoding.
This should allow cassettes recorded on 1.8 to work on 1.9.

Closes #149.
be4ca6c
@myronmarston Just force encode to ASCII-8BIT.
Encoding to ASCII-8BIT is nonsensical since it just means "binary".
1898467
@myronmarston RSpec 2.9.0 is out. 5d3b3df
@myronmarston Excon 0.13 is out and VCR works fine with it. ba10bb5
@myronmarston Fix faraday middleware so that it plays back parallel requests properly. 095ed4e
@myronmarston Build 2-0-stable branch. 2677b15
@myronmarston Add 2-0-stable changelog. 4958f81
@myronmarston 2.0.1 release. 4a8c67d
Commits on Apr 03, 2012
@myronmarston Raise a helpful message if #use_cassette is called with no block.
Previously, doing so would raise a confusing error:

  NoMethodError: undefined method `arity' for nil:NilClass
a3747a8
Commits on Apr 19, 2012
@myronmarston Fix changelog to reflect 2.0.1 release. d9d0598
View
1 .travis.yml
@@ -17,6 +17,7 @@ branches:
- master
- 1-x-stable
- travis-testing
+ - 2-0-stable
matrix:
allow_failures:
- rvm: jruby-19mode
View
17 CHANGELOG.md
@@ -1,6 +1,17 @@
-## In git
-
-[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0...master)
+## 2.0.1 (March 30, 2012)
+
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0...v2.0.1)
+
+* Fix encoding logic to not attempt to encode the request or response
+ body on deserialization if there is no encoding specified. This should
+ allow cassettes recorded on 1.8 to work on 1.9. Thanks to
+ [Kevin Menard](https://github.com/nirvdrum) for reporting the bug.
+* Fix Excon adapter to fix a bug with Excon 0.11 and greater. When you
+ passed a block to an excon request, the response body would not be
+ recorded.
+* Fix Faraday middleware so that it plays back parallel requests
+ properly. Thanks to [Dave Weiser](https://github.com/davidann) for
+ reporting this bug.
## 2.0.0 (March 2, 2012)
View
6 lib/vcr.rb
@@ -144,6 +144,12 @@ def eject_cassette
# @see #insert_cassette
# @see #eject_cassette
def use_cassette(name, options = {}, &block)
+ unless block
+ raise ArgumentError, "`VCR.use_cassette` requires a block. " +
+ "If you cannot wrap your code in a block, use " +
+ "`VCR.insert_cassette` / `VCR.eject_cassette` instead."
+ end
+
cassette = insert_cassette(name, options)
begin
View
4 lib/vcr/library_hooks/excon.rb
@@ -2,7 +2,7 @@
require 'vcr/request_handler'
require 'excon'
-VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.10').check_version!
+VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.13').check_version!
module VCR
class LibraryHooks
@@ -52,7 +52,7 @@ def real_request_params
# a raw response, and then the main request (with :mock => true) can
# handle failure/retry on its own with its set options.
params.merge(:mock => false, :retry_limit => 0).tap do |p|
- [:expects, :idempotent, :instrumentor_name, :instrumentor].each do |key|
+ [:expects, :idempotent, :instrumentor_name, :instrumentor, :response_block, :request_block].each do |key|
p.delete(key)
end
end
View
2 lib/vcr/middleware/faraday.rb
@@ -83,7 +83,7 @@ def on_stubbed_request
env.update :status => stubbed_response.status.code, :body => stubbed_response.body
faraday_response = ::Faraday::Response.new
- faraday_response.finish(env) unless env[:parallel_manager]
+ faraday_response.finish(env)
env[:response] = faraday_response
end
View
8 lib/vcr/structs.rb
@@ -32,7 +32,13 @@ def force_encode_string(string, encoding)
end
def try_encode_string(string, encoding)
- return string if string.encoding.name == encoding
+ return string if encoding.nil? || string.encoding.name == encoding
+
+ # ASCII-8BIT just means binary, so encoding to it is nonsensical
+ # and yet "\u00f6".encode("ASCII-8BIT") raises an error.
+ # Instead, we'll force encode it (essentially just tagging it as binary)
+ return string.force_encoding(encoding) if encoding == "ASCII-8BIT"
+
string.encode(encoding)
rescue EncodingError => e
struct_type = name.split('::').last.downcase
View
2 lib/vcr/version.rb
@@ -10,7 +10,7 @@ module VCR
# * `parts` [Array<Integer>] List of the version parts.
def version
@version ||= begin
- string = '2.0.0'
+ string = '2.0.1'
def string.parts
split('.').map { |p| p.to_i }
View
8 spec/spec_helper.rb
@@ -48,9 +48,11 @@ def reset!(hook = :fakeweb)
config.treat_symbols_as_metadata_keys_with_true_values = true
tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__)
- config.before(:each, :skip_vcr_reset => lambda { |v| v != true }) do
- VCR.reset!
- VCR.configuration.cassette_library_dir = tmp_dir
+ config.before(:each) do
+ unless example.metadata[:skip_vcr_reset]
+ VCR.reset!
+ VCR.configuration.cassette_library_dir = tmp_dir
+ end
end
config.after(:each) do
View
4 spec/vcr/library_hooks/excon_spec.rb
@@ -32,9 +32,9 @@
chunks = []
VCR.use_cassette('excon_streaming', :record => :once) do
- Excon.get("http://localhost:#{VCR::SinatraApp.port}/foo") do |chunk, remaining_bytes, total_bytes|
+ Excon.get "http://localhost:#{VCR::SinatraApp.port}/foo", :response_block => lambda { |chunk, remaining_bytes, total_bytes|
chunks << chunk
- end
+ }
end
chunks.join
View
22 spec/vcr/middleware/faraday_spec.rb
@@ -13,10 +13,28 @@
include VCRStubHelpers
let(:parallel_manager) { ::Faraday::Adapter::Typhoeus.setup_parallel_manager }
let(:connection) { ::Faraday.new { |b| b.adapter :typhoeus } }
+ let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
- shared_examples_for "exclusive library hook" do
- let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
+ it 'works correctly with multiple parallel requests' do
+ recorded, played_back = [1, 2].map do
+ responses = []
+
+ VCR.use_cassette("multiple_parallel") do
+ connection.in_parallel(parallel_manager) do
+ responses << connection.get(request_url)
+ responses << connection.get(request_url)
+ end
+ end
+
+ responses.map(&:body)
+ end
+
+ # there should be no blanks
+ recorded.select { |r| r.to_s == '' }.should eq([])
+ played_back.should eq(recorded)
+ end
+ shared_examples_for "exclusive library hook" do
def make_request
connection.in_parallel(parallel_manager) { connection.get(request_url) }
end
View
23 spec/vcr/structs_spec.rb
@@ -162,6 +162,29 @@ def body_hash(key, value)
i.response.body.encoding.name.should eq("ISO-8859-1")
end
+ it 'does not attempt to encode the string when there is no encoding given (i.e. if the cassette was recorded on ruby 1.8)' do
+ string = 'foo'
+ string.force_encoding("ISO-8859-1")
+ hash['request']['body'] = { 'string' => string }
+
+ i = HTTPInteraction.from_hash(hash)
+ i.request.body.should eq('foo')
+ i.request.body.encoding.name.should eq("ISO-8859-1")
+ end
+
+ it 'force encodes to ASCII-8BIT (since it just means "no encoding" or binary)' do
+ string = "\u00f6"
+ string.encode("UTF-8")
+ string.should be_valid_encoding
+ hash['request']['body'] = { 'string' => string, 'encoding' => 'ASCII-8BIT' }
+
+ Request.should_not_receive(:warn)
+ i = HTTPInteraction.from_hash(hash)
+ i.request.body.should eq(string)
+ i.request.body.bytes.to_a.should eq(string.bytes.to_a)
+ i.request.body.encoding.name.should eq("ASCII-8BIT")
+ end
+
context 'when the string cannot be encoded as the original encoding' do
before do
Request.stub(:warn)
View
6 spec/vcr_spec.rb
@@ -95,6 +95,12 @@ def insert_cassette(name = :cassette_test)
VCR.should_not_receive(:eject_cassette)
expect { VCR.use_cassette(:test) { } }.to raise_error(StandardError, 'Boom!')
end
+
+ it 'raises a helpful error if no block is given' do
+ expect {
+ VCR.use_cassette(:test)
+ }.to raise_error(/requires a block/)
+ end
end
describe '.http_interactions' do
View
10 vcr.gemspec
@@ -17,21 +17,21 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.8.7'
s.required_rubygems_version = '>= 1.3.5'
- s.add_development_dependency 'bundler', '~> 1.0.7'
+ s.add_development_dependency 'bundler', '>= 1.0.7'
s.add_development_dependency 'rake', '~> 0.9.2'
s.add_development_dependency 'cucumber', '~> 1.1.4'
s.add_development_dependency 'aruba', '~> 0.4.11'
- s.add_development_dependency 'rspec', '~> 2.8.0'
+ s.add_development_dependency 'rspec', '~> 2.9.0'
s.add_development_dependency 'shoulda', '~> 2.9.2'
s.add_development_dependency 'fakeweb', '~> 1.3.0'
- s.add_development_dependency 'webmock', '~> 1.8.0'
+ s.add_development_dependency 'webmock', '~> 1.8.3'
s.add_development_dependency 'faraday', '~> 0.8.0.rc2'
s.add_development_dependency 'httpclient', '~> 2.1.5.2'
- s.add_development_dependency 'excon', '>= 0.9.6', '< 1.0'
+ s.add_development_dependency 'excon', '>= 0.11.0', '< 1.0'
s.add_development_dependency 'timecop', '~> 0.3.5'
s.add_development_dependency 'rack', '~> 1.3.6'
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
unless RUBY_PLATFORM == 'java'
s.add_development_dependency 'patron', '~> 0.4.15'
- s.add_development_dependency 'em-http-request', '~> 1.0.1'
+ s.add_development_dependency 'em-http-request', '~> 1.0.2'
s.add_development_dependency 'curb', '~> 0.8.0'
s.add_development_dependency 'typhoeus', '~> 0.3.3'
s.add_development_dependency 'yajl-ruby', '~> 1.1.0'

No commit comments for this range

Something went wrong with that request. Please try again.