vcr 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -17,6 +17,7 @@ branches:
17
17
  - master
18
18
  - 1-x-stable
19
19
  - travis-testing
20
+ - 2-0-stable
20
21
  matrix:
21
22
  allow_failures:
22
23
  - rvm: jruby-19mode
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  ## In git
2
2
 
3
- [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0...master)
3
+ [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.0.0...2-0-stable)
4
+
5
+ * Fix encoding logic to not attempt to encode the request or response
6
+ body on deserialization if there is no encoding specified. This should
7
+ allow cassettes recorded on 1.8 to work on 1.9. Thanks to
8
+ [Kevin Menard](https://github.com/nirvdrum) for reporting the bug.
9
+ * Fix Excon adapter to fix a bug with Excon 0.11 and greater. When you
10
+ passed a block to an excon request, the response body would not be
11
+ recorded.
12
+ * Fix Faraday middleware so that it plays back parallel requests
13
+ properly. Thanks to [Dave Weiser](https://github.com/davidann) for
14
+ reporting this bug.
4
15
 
5
16
  ## 2.0.0 (March 2, 2012)
6
17
 
data/README.md CHANGED
@@ -155,17 +155,21 @@ Thanks also to the following people who have contributed patches or helpful sugg
155
155
  * [Sathya Sekaran](https://github.com/sfsekaran)
156
156
  * [Wesley Beary](https://github.com/geemus)
157
157
 
158
- ## Similar Libraries
158
+ ## Ports in other languages
159
159
 
160
160
  * [Betamax](https://github.com/robfletcher/betamax) (Groovy)
161
161
  * [VCR.js](https://github.com/elcuervo/vcr.js) (JavaScript)
162
162
  * [TapeDeck.js](https://github.com/EndangeredMassa/TapeDeck.js) (JavaScript)
163
163
  * [Mimic](https://github.com/acoulton/mimic) (PHP/Kohana)
164
- * [Ephemeral Response](https://github.com/sandro/ephemeral_response) (Ruby)
165
- * [Net::HTTP Spy](http://github.com/martinbtt/net-http-spy) (Ruby)
166
- * [NetRecorder](https://github.com/chrisyoung/netrecorder) (Ruby)
167
- * [Stale Fish](https://github.com/jsmestad/stale_fish) (Ruby)
168
- * [WebFixtures](http://github.com/trydionel/web_fixtures) (Ruby)
164
+
165
+ ## Similar Libraries in Ruby
166
+
167
+ * [Ephemeral Response](https://github.com/sandro/ephemeral_response)
168
+ * [Net::HTTP Spy](http://github.com/martinbtt/net-http-spy)
169
+ * [NetRecorder](https://github.com/chrisyoung/netrecorder)
170
+ * [Stale Fish](https://github.com/jsmestad/stale_fish)
171
+ * [WebFixtures](http://github.com/trydionel/web_fixtures)
172
+ * [REST-assured](https://github.com/BBC/REST-assured)
169
173
 
170
174
  ## Copyright
171
175
 
data/Upgrade.md CHANGED
@@ -49,8 +49,7 @@ re-record your cassettes if you are able.
49
49
 
50
50
  ## Custom Request Matchers
51
51
 
52
- VCR 2.0 allows any callable (an object that responds to #call, such as a lambda)
53
- to be used as a request matcher:
52
+ VCR 2.0 allows you to register custom request matchers:
54
53
 
55
54
  ``` ruby
56
55
  VCR.configure do |c|
@@ -60,6 +59,19 @@ VCR.configure do |c|
60
59
  end
61
60
  ```
62
61
 
62
+ You can also pass any callable (an object that responds to #call, such as a lambda)
63
+ to the `:match_requests_on` option:
64
+
65
+ ``` ruby
66
+ port_matcher = lambda do |request_1, request_2|
67
+ URI(request_1.uri).port == URI(request_2.uri).port
68
+ end
69
+
70
+ VCR.use_cassette("example", :match_requests_on => [:host, port_matcher, :method]) do
71
+ # make an HTTP request
72
+ end
73
+ ```
74
+
63
75
  In addition, a helper method is provided for generating a custom
64
76
  matcher that ignores one or more query parameters:
65
77
 
@@ -74,7 +86,8 @@ end
74
86
 
75
87
  VCR 2.0 supports multiple serializers. `:yaml`, `:json`, `:psych` and
76
88
  `:syck` are supported out of the box, and it's easy to implement your
77
- own:
89
+ own. Custom serializers must implement `#file_extension`, `#serialize`
90
+ and `#deserialize`:
78
91
 
79
92
  ``` ruby
80
93
  VCR.use_cassette("example", :serialize_with => :json) do
@@ -119,17 +132,15 @@ VCR.configure do |c|
119
132
  end
120
133
 
121
134
  # around_http_request only works on ruby 1.9
122
- VCR.configure do |c|
123
- c.around_http_request do |request|
124
- uri = URI(request.uri)
125
- if uri.host == 'api.geocoder.com'
126
- # extract an address like "1700 E Pine St, Seattle, WA"
127
- # from a query like "address=1700+E+Pine+St%2C+Seattle%2C+WA"
128
- address = CGI.unescape(uri.query.split('=').last)
129
- VCR.use_cassette("geocoding/#{address}", &request)
130
- else
131
- request.proceed
132
- end
135
+ c.around_http_request do |request|
136
+ uri = URI(request.uri)
137
+ if uri.host == 'api.geocoder.com'
138
+ # extract an address like "1700 E Pine St, Seattle, WA"
139
+ # from a query like "address=1700+E+Pine+St%2C+Seattle%2C+WA"
140
+ address = CGI.unescape(uri.query.split('=').last)
141
+ VCR.use_cassette("geocoding/#{address}", &request)
142
+ else
143
+ request.proceed
133
144
  end
134
145
  end
135
146
  end
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.setup
4
- require 'limited_red/plugins/cucumber' unless ENV['CI']
4
+ require 'limited_red/plugins/cucumber'
5
5
 
6
6
  require 'ruby-debug' if !defined?(RUBY_ENGINE) && RUBY_VERSION != '1.9.3' && !ENV['CI']
7
7
 
@@ -2,7 +2,7 @@ require 'vcr/util/version_checker'
2
2
  require 'vcr/request_handler'
3
3
  require 'excon'
4
4
 
5
- VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.10').check_version!
5
+ VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.13').check_version!
6
6
 
7
7
  module VCR
8
8
  class LibraryHooks
@@ -52,7 +52,7 @@ module VCR
52
52
  # a raw response, and then the main request (with :mock => true) can
53
53
  # handle failure/retry on its own with its set options.
54
54
  params.merge(:mock => false, :retry_limit => 0).tap do |p|
55
- [:expects, :idempotent, :instrumentor_name, :instrumentor].each do |key|
55
+ [:expects, :idempotent, :instrumentor_name, :instrumentor, :response_block, :request_block].each do |key|
56
56
  p.delete(key)
57
57
  end
58
58
  end
@@ -83,7 +83,7 @@ module VCR
83
83
  env.update :status => stubbed_response.status.code, :body => stubbed_response.body
84
84
 
85
85
  faraday_response = ::Faraday::Response.new
86
- faraday_response.finish(env) unless env[:parallel_manager]
86
+ faraday_response.finish(env)
87
87
  env[:response] = faraday_response
88
88
  end
89
89
 
data/lib/vcr/structs.rb CHANGED
@@ -32,7 +32,13 @@ module VCR
32
32
  end
33
33
 
34
34
  def try_encode_string(string, encoding)
35
- return string if string.encoding.name == encoding
35
+ return string if encoding.nil? || string.encoding.name == encoding
36
+
37
+ # ASCII-8BIT just means binary, so encoding to it is nonsensical
38
+ # and yet "\u00f6".encode("ASCII-8BIT") raises an error.
39
+ # Instead, we'll force encode it (essentially just tagging it as binary)
40
+ return string.force_encoding(encoding) if encoding == "ASCII-8BIT"
41
+
36
42
  string.encode(encoding)
37
43
  rescue EncodingError => e
38
44
  struct_type = name.split('::').last.downcase
data/lib/vcr/version.rb CHANGED
@@ -10,7 +10,7 @@ module VCR
10
10
  # * `parts` [Array<Integer>] List of the version parts.
11
11
  def version
12
12
  @version ||= begin
13
- string = '2.0.0'
13
+ string = '2.0.1'
14
14
 
15
15
  def string.parts
16
16
  split('.').map { |p| p.to_i }
data/spec/spec_helper.rb CHANGED
@@ -48,9 +48,11 @@ RSpec.configure do |config|
48
48
  config.treat_symbols_as_metadata_keys_with_true_values = true
49
49
 
50
50
  tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__)
51
- config.before(:each, :skip_vcr_reset => lambda { |v| v != true }) do
52
- VCR.reset!
53
- VCR.configuration.cassette_library_dir = tmp_dir
51
+ config.before(:each) do
52
+ unless example.metadata[:skip_vcr_reset]
53
+ VCR.reset!
54
+ VCR.configuration.cassette_library_dir = tmp_dir
55
+ end
54
56
  end
55
57
 
56
58
  config.after(:each) do
@@ -32,9 +32,9 @@ describe "Excon hook", :with_monkey_patches => :excon do
32
32
  chunks = []
33
33
 
34
34
  VCR.use_cassette('excon_streaming', :record => :once) do
35
- Excon.get("http://localhost:#{VCR::SinatraApp.port}/foo") do |chunk, remaining_bytes, total_bytes|
35
+ Excon.get "http://localhost:#{VCR::SinatraApp.port}/foo", :response_block => lambda { |chunk, remaining_bytes, total_bytes|
36
36
  chunks << chunk
37
- end
37
+ }
38
38
  end
39
39
 
40
40
  chunks.join
@@ -13,10 +13,28 @@ describe VCR::Middleware::Faraday do
13
13
  include VCRStubHelpers
14
14
  let(:parallel_manager) { ::Faraday::Adapter::Typhoeus.setup_parallel_manager }
15
15
  let(:connection) { ::Faraday.new { |b| b.adapter :typhoeus } }
16
+ let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
16
17
 
17
- shared_examples_for "exclusive library hook" do
18
- let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
18
+ it 'works correctly with multiple parallel requests' do
19
+ recorded, played_back = [1, 2].map do
20
+ responses = []
21
+
22
+ VCR.use_cassette("multiple_parallel") do
23
+ connection.in_parallel(parallel_manager) do
24
+ responses << connection.get(request_url)
25
+ responses << connection.get(request_url)
26
+ end
27
+ end
28
+
29
+ responses.map(&:body)
30
+ end
31
+
32
+ # there should be no blanks
33
+ recorded.select { |r| r.to_s == '' }.should eq([])
34
+ played_back.should eq(recorded)
35
+ end
19
36
 
37
+ shared_examples_for "exclusive library hook" do
20
38
  def make_request
21
39
  connection.in_parallel(parallel_manager) { connection.get(request_url) }
22
40
  end
@@ -162,6 +162,29 @@ module VCR
162
162
  i.response.body.encoding.name.should eq("ISO-8859-1")
163
163
  end
164
164
 
165
+ 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
166
+ string = 'foo'
167
+ string.force_encoding("ISO-8859-1")
168
+ hash['request']['body'] = { 'string' => string }
169
+
170
+ i = HTTPInteraction.from_hash(hash)
171
+ i.request.body.should eq('foo')
172
+ i.request.body.encoding.name.should eq("ISO-8859-1")
173
+ end
174
+
175
+ it 'force encodes to ASCII-8BIT (since it just means "no encoding" or binary)' do
176
+ string = "\u00f6"
177
+ string.encode("UTF-8")
178
+ string.should be_valid_encoding
179
+ hash['request']['body'] = { 'string' => string, 'encoding' => 'ASCII-8BIT' }
180
+
181
+ Request.should_not_receive(:warn)
182
+ i = HTTPInteraction.from_hash(hash)
183
+ i.request.body.should eq(string)
184
+ i.request.body.bytes.to_a.should eq(string.bytes.to_a)
185
+ i.request.body.encoding.name.should eq("ASCII-8BIT")
186
+ end
187
+
165
188
  context 'when the string cannot be encoded as the original encoding' do
166
189
  before do
167
190
  Request.stub(:warn)
data/vcr.gemspec CHANGED
@@ -17,33 +17,33 @@ Gem::Specification.new do |s|
17
17
  s.required_ruby_version = '>= 1.8.7'
18
18
  s.required_rubygems_version = '>= 1.3.5'
19
19
 
20
- s.add_development_dependency 'bundler', '~> 1.0.7'
20
+ s.add_development_dependency 'bundler', '>= 1.0.7'
21
21
  s.add_development_dependency 'rake', '~> 0.9.2'
22
22
 
23
23
  s.add_development_dependency 'cucumber', '~> 1.1.4'
24
24
  s.add_development_dependency 'aruba', '~> 0.4.11'
25
25
 
26
- s.add_development_dependency 'rspec', '~> 2.8.0'
26
+ s.add_development_dependency 'rspec', '~> 2.9.0'
27
27
  s.add_development_dependency 'shoulda', '~> 2.9.2'
28
28
 
29
29
  s.add_development_dependency 'fakeweb', '~> 1.3.0'
30
- s.add_development_dependency 'webmock', '~> 1.8.0'
30
+ s.add_development_dependency 'webmock', '~> 1.8.3'
31
31
 
32
32
  s.add_development_dependency 'faraday', '~> 0.8.0.rc2'
33
33
  s.add_development_dependency 'httpclient', '~> 2.1.5.2'
34
- s.add_development_dependency 'excon', '>= 0.9.6', '< 1.0'
34
+ s.add_development_dependency 'excon', '>= 0.11.0', '< 1.0'
35
35
 
36
36
  s.add_development_dependency 'timecop', '~> 0.3.5'
37
37
  s.add_development_dependency 'rack', '~> 1.3.6'
38
38
  s.add_development_dependency 'sinatra', '~> 1.3.2'
39
39
  s.add_development_dependency 'multi_json', '~> 1.0.3'
40
40
  s.add_development_dependency 'json', '~> 1.6.5'
41
- s.add_development_dependency 'limited_red', '~> 0.3.7'
41
+ s.add_development_dependency 'limited_red', '~> 0.3.8'
42
42
  s.add_development_dependency 'simplecov', '~> 0.5.3'
43
43
 
44
44
  unless RUBY_PLATFORM == 'java'
45
45
  s.add_development_dependency 'patron', '~> 0.4.15'
46
- s.add_development_dependency 'em-http-request', '~> 1.0.1'
46
+ s.add_development_dependency 'em-http-request', '~> 1.0.2'
47
47
  s.add_development_dependency 'curb', '~> 0.8.0'
48
48
  s.add_development_dependency 'typhoeus', '~> 0.3.3'
49
49
  s.add_development_dependency 'yajl-ruby', '~> 1.1.0'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Myron Marston
@@ -15,13 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-02 00:00:00 Z
18
+ date: 2012-03-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  hash: 25
27
27
  segments:
@@ -87,12 +87,12 @@ dependencies:
87
87
  requirements:
88
88
  - - ~>
89
89
  - !ruby/object:Gem::Version
90
- hash: 47
90
+ hash: 43
91
91
  segments:
92
92
  - 2
93
- - 8
93
+ - 9
94
94
  - 0
95
- version: 2.8.0
95
+ version: 2.9.0
96
96
  name: rspec
97
97
  type: :development
98
98
  prerelease: false
@@ -135,12 +135,12 @@ dependencies:
135
135
  requirements:
136
136
  - - ~>
137
137
  - !ruby/object:Gem::Version
138
- hash: 55
138
+ hash: 49
139
139
  segments:
140
140
  - 1
141
141
  - 8
142
- - 0
143
- version: 1.8.0
142
+ - 3
143
+ version: 1.8.3
144
144
  name: webmock
145
145
  type: :development
146
146
  prerelease: false
@@ -186,12 +186,12 @@ dependencies:
186
186
  requirements:
187
187
  - - ">="
188
188
  - !ruby/object:Gem::Version
189
- hash: 55
189
+ hash: 51
190
190
  segments:
191
191
  - 0
192
- - 9
193
- - 6
194
- version: 0.9.6
192
+ - 11
193
+ - 0
194
+ version: 0.11.0
195
195
  - - <
196
196
  - !ruby/object:Gem::Version
197
197
  hash: 15
@@ -289,12 +289,12 @@ dependencies:
289
289
  requirements:
290
290
  - - ~>
291
291
  - !ruby/object:Gem::Version
292
- hash: 29
292
+ hash: 3
293
293
  segments:
294
294
  - 0
295
295
  - 3
296
- - 7
297
- version: 0.3.7
296
+ - 8
297
+ version: 0.3.8
298
298
  name: limited_red
299
299
  type: :development
300
300
  prerelease: false
@@ -337,12 +337,12 @@ dependencies:
337
337
  requirements:
338
338
  - - ~>
339
339
  - !ruby/object:Gem::Version
340
- hash: 21
340
+ hash: 19
341
341
  segments:
342
342
  - 1
343
343
  - 0
344
- - 1
345
- version: 1.0.1
344
+ - 2
345
+ version: 1.0.2
346
346
  name: em-http-request
347
347
  type: :development
348
348
  prerelease: false