vcr 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.0...master)
4
4
 
5
+ ## 2.2.1 (June 13, 2012)
6
+
7
+ [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.0...v2.2.1)
8
+
9
+ Bug Fixes:
10
+
11
+ * Fix matcher generated by `VCR.request_matchers.uri_without_params` so that
12
+ it handles URIs w/o query params properly. Previously, it would allow any
13
+ two URIs w/o query params to match, even if the hosts or paths
14
+ differed.
15
+
5
16
  ## 2.2.0 (May 31, 2012)
6
17
 
7
18
  [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.1.1...v2.2.0)
data/README.md CHANGED
@@ -38,7 +38,7 @@ maintenance) and accurate (the response will contain the same headers and body y
38
38
  following are supported:
39
39
  * [FakeWeb](https://github.com/chrisk/fakeweb)
40
40
  * [WebMock](https://github.com/bblimke/webmock)
41
- * [Typhoeus](https://github.com/dbalatero/typhoeus)
41
+ * [Typhoeus](https://github.com/typhoeus/typhoeus)
42
42
  * [Faraday](https://github.com/technoweenie/faraday)
43
43
  * [Excon](https://github.com/geemus/excon)
44
44
  * Supports multiple HTTP libraries:
@@ -47,7 +47,7 @@ maintenance) and accurate (the response will contain the same headers and body y
47
47
  * [HTTPClient](http://github.com/nahi/httpclient) (when using WebMock)
48
48
  * [em-http-request](http://github.com/igrigorik/em-http-request) (when using WebMock)
49
49
  * [Net::HTTP](http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html) (when using FakeWeb and WebMock)
50
- * [Typhoeus](https://github.com/dbalatero/typhoeus) (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
50
+ * [Typhoeus](https://github.com/typhoeus/typhoeus) (Typhoeus::Hydra, but not Typhoeus::Easy or Typhoeus::Multi)
51
51
  * [Excon](https://github.com/geemus/excon)
52
52
  * [Faraday](https://github.com/technoweenie/faraday)
53
53
  * And of course any library built on Net::HTTP, such as [Mechanize](http://github.com/tenderlove/mechanize),
@@ -127,7 +127,7 @@ yard server --reload
127
127
  * [Chris Kampmeier](http://github.com/chrisk) for [FakeWeb](http://github.com/chrisk/fakeweb).
128
128
  * [Chris Young](http://github.com/chrisyoung) for [NetRecorder](http://github.com/chrisyoung/netrecorder),
129
129
  the inspiration for VCR.
130
- * [David Balatero](https://github.com/dbalatero) for help with [Typhoeus](https://github.com/pauldix/typhoeus)
130
+ * [David Balatero](https://github.com/dbalatero) for help with [Typhoeus](https://github.com/typhoeus/typhoeus)
131
131
  support.
132
132
  * [Wesley Beary](https://github.com/geemus) for help with [Excon](https://github.com/geemus/excon)
133
133
  support.
@@ -40,9 +40,9 @@ Feature: Cassette format
40
40
 
41
41
  You can also register a custom serializer using:
42
42
 
43
- VCR.configure do |config|
44
- config.cassette_serializers[:my_custom_serializer] = my_serializer
45
- end
43
+ VCR.configure do |config|
44
+ config.cassette_serializers[:my_custom_serializer] = my_serializer
45
+ end
46
46
 
47
47
  Your serializer must implement the following methods:
48
48
 
@@ -9,7 +9,10 @@ Feature: URI without param(s)
9
9
  common need to match on a URI and ignore particular query parameters, VCR
10
10
  provides an easier way:
11
11
 
12
- :match_requests_on => [:method, VCR.request_matchers.uri_without_param(:timestamp)]
12
+ :match_requests_on => [
13
+ :method,
14
+ VCR.request_matchers.uri_without_param(:timestamp)
15
+ ]
13
16
 
14
17
  `uri_without_param` also has a plural alias (i.e. `uri_without_params(:timestamp, :session)`)
15
18
 
@@ -70,7 +73,8 @@ Feature: URI without param(s)
70
73
  c.hook_into :fakeweb
71
74
  c.cassette_library_dir = 'cassettes'
72
75
  c.default_cassette_options = {
73
- :match_requests_on => [:method, VCR.request_matchers.uri_without_param(:timestamp)]
76
+ :match_requests_on => [:method,
77
+ VCR.request_matchers.uri_without_param(:timestamp)]
74
78
  }
75
79
  end
76
80
 
@@ -79,11 +83,13 @@ Feature: URI without param(s)
79
83
  end
80
84
 
81
85
  VCR.use_cassette('example') do
82
- puts "Response for bar: " + response_body_for(:get, search_uri("bar"))
86
+ puts "Response for bar: " +
87
+ response_body_for(:get, search_uri("bar"))
83
88
  end
84
89
 
85
90
  VCR.use_cassette('example') do
86
- puts "Response for foo: " + response_body_for(:get, search_uri("foo"))
91
+ puts "Response for foo: " +
92
+ response_body_for(:get, search_uri("foo"))
87
93
  end
88
94
  """
89
95
  When I run `ruby uri_without_param_matcher.rb`
@@ -76,7 +76,8 @@ Feature: Usage with RSpec metadata
76
76
  """ruby
77
77
  require 'spec_helper'
78
78
 
79
- describe "Using an options hash", :vcr => { :cassette_name => "example", :record => :new_episodes } do
79
+ vcr_options = { :cassette_name => "example", :record => :new_episodes }
80
+ describe "Using an options hash", :vcr => vcr_options do
80
81
  it 'uses the provided cassette name' do
81
82
  VCR.current_cassette.name.should == "example"
82
83
  end
data/lib/vcr.rb CHANGED
@@ -81,7 +81,7 @@ module VCR
81
81
  # @option options :allow_playback_repeats [Boolean] Whether or not to
82
82
  # allow a single HTTP interaction to be played back multiple times.
83
83
  # Defaults to false.
84
- # @options options :allow_unused_http_interactions [Boolean] If set to
84
+ # @option options :allow_unused_http_interactions [Boolean] If set to
85
85
  # false, an error will be raised if a cassette is ejected before all
86
86
  # previously recorded HTTP interactions have been used.
87
87
  # Defaults to true.
@@ -11,7 +11,7 @@ module VCR
11
11
  # Faraday.
12
12
  #
13
13
  # @note You can either insert this middleware into the Faraday middleware stack
14
- # yourself or configure {VCR::Configuration#hook_into} to hook into +:faraday+.
14
+ # yourself or configure {VCR::Configuration#hook_into} to hook into `:faraday`.
15
15
  class Faraday
16
16
  include VCR::Deprecations::Middleware::Faraday
17
17
 
@@ -19,7 +19,7 @@ module VCR
19
19
  class URIWithoutParamsMatcher < Struct.new(:params_to_ignore)
20
20
  def partial_uri_from(request)
21
21
  URI(request.uri).tap do |uri|
22
- break unless uri.query # ignore uris without params, e.g. "http://example.com/"
22
+ return request.uri unless uri.query # ignore uris without params, e.g. "http://example.com/"
23
23
 
24
24
  uri.query = uri.query.split('&').tap { |params|
25
25
  params.map! do |p|
@@ -14,7 +14,7 @@ module VCR
14
14
  #
15
15
  module Macros
16
16
 
17
- # Sets up a +before+ and +after+ hook that will insert and eject a
17
+ # Sets up a `before` and `after` hook that will insert and eject a
18
18
  # cassette, respectively.
19
19
  #
20
20
  # @example
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.2.0'
13
+ string = '2.2.1'
14
14
 
15
15
  def string.parts
16
16
  split('.').map { |p| p.to_i }
@@ -16,6 +16,7 @@ HTTP_LIBRARY_ADAPTERS['net/http'] = Module.new do
16
16
  def self.http_library_name; 'Net::HTTP'; end
17
17
 
18
18
  def get_body_string(response); response.body; end
19
+ alias get_body_object get_body_string
19
20
 
20
21
  def get_header(header_key, response)
21
22
  response.get_fields(header_key)
@@ -46,6 +47,7 @@ HTTP_LIBRARY_ADAPTERS['patron'] = Module.new do
46
47
  def self.http_library_name; 'Patron'; end
47
48
 
48
49
  def get_body_string(response); response.body; end
50
+ alias get_body_object get_body_string
49
51
 
50
52
  def get_header(header_key, response)
51
53
  response.headers[header_key]
@@ -69,6 +71,10 @@ HTTP_LIBRARY_ADAPTERS['httpclient'] = Module.new do
69
71
  string.respond_to?(:read) ? string.read : string
70
72
  end
71
73
 
74
+ def get_body_object(response)
75
+ response.body
76
+ end
77
+
72
78
  def get_header(header_key, response)
73
79
  response.header[header_key]
74
80
  end
@@ -88,6 +94,7 @@ HTTP_LIBRARY_ADAPTERS['em-http-request'] = Module.new do
88
94
  def get_body_string(response)
89
95
  response.response
90
96
  end
97
+ alias get_body_object get_body_string
91
98
 
92
99
  def get_header(header_key, response)
93
100
  values = response.response_header[header_key.upcase.gsub('-', '_')]
@@ -114,6 +121,7 @@ HTTP_LIBRARY_ADAPTERS['curb'] = Module.new do
114
121
  def get_body_string(response)
115
122
  response.body_str
116
123
  end
124
+ alias get_body_object get_body_string
117
125
 
118
126
  def get_header(header_key, response)
119
127
  headers = response.header_str.split("\r\n")[1..-1]
@@ -149,6 +157,7 @@ HTTP_LIBRARY_ADAPTERS['typhoeus'] = Module.new do
149
157
  def get_body_string(response)
150
158
  response.body
151
159
  end
160
+ alias get_body_object get_body_string
152
161
 
153
162
  def get_header(header_key, response)
154
163
  response.headers_hash[header_key]
@@ -169,6 +178,7 @@ HTTP_LIBRARY_ADAPTERS['excon'] = Module.new do
169
178
  def get_body_string(response)
170
179
  response.body
171
180
  end
181
+ alias get_body_object get_body_string
172
182
 
173
183
  def get_header(header_key, response)
174
184
  response.headers[header_key]
@@ -198,6 +208,7 @@ end
198
208
  def get_body_string(response)
199
209
  response.body
200
210
  end
211
+ alias get_body_object get_body_string
201
212
 
202
213
  def get_header(header_key, response)
203
214
  value = response.headers[header_key]
@@ -55,6 +55,20 @@ shared_examples_for "a hook into an HTTP library" do |library_hook_name, library
55
55
  test_record_and_playback "with spaces encoded as %20", "q=a%20b"
56
56
  test_record_and_playback "with a complex escaped query param", "q=#{CGI.escape("A&(! 234k !@ kasdj232\#$ kjw35")}"
57
57
 
58
+ it 'plays back an empty body response exactly as it was recorded (e.g. nil vs empty string)' do
59
+ pending "awaiting an external fix", :if => library.gsub('_', '/').include?('net/http') do
60
+ get_body = lambda do
61
+ VCR.use_cassette('empty_body', :record => :once) do
62
+ get_body_object make_http_request(:get, "http://localhost:#{VCR::SinatraApp.port}/204")
63
+ end
64
+ end
65
+
66
+ recorded = get_body.call
67
+ played_back = get_body.call
68
+ played_back.should eq(recorded)
69
+ end
70
+ end
71
+
58
72
  describe 'making an HTTP request' do
59
73
  let(:status) { VCR::ResponseStatus.new(200, 'OK') }
60
74
  let(:interaction) { VCR::HTTPInteraction.new(request, response) }
@@ -34,6 +34,10 @@ module VCR
34
34
  'header set'
35
35
  end
36
36
 
37
+ get '/204' do
38
+ status 204
39
+ end
40
+
37
41
  # we use a global counter so that every response is different;
38
42
  # this ensures that the test demonstrates that the response
39
43
  # is being played back (and not running a 2nd real request)
@@ -134,6 +134,13 @@ module VCR
134
134
  request_with(:uri => 'http://example.com/search')
135
135
  ).should be_true
136
136
  end
137
+
138
+ it 'does not match two requests with URIs that have no params but different paths' do
139
+ subject[subject.send(meth, :foo, :bar)].matches?(
140
+ request_with(:uri => 'http://example.com/foo'),
141
+ request_with(:uri => 'http://example.com/bar')
142
+ ).should be_false
143
+ end
137
144
  end
138
145
  end
139
146
 
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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 0
10
- version: 2.2.0
9
+ - 1
10
+ version: 2.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Myron Marston
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-31 00:00:00 Z
18
+ date: 2012-06-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement