vcr 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.2...master)
4
4
 
5
+ Bug Fixes:
6
+
7
+ * Fix FakeWeb library hook so that it properly handles the case where
8
+ multiple requests are made using the same Net::HTTP request object.
9
+ Previously, a `NoMethodError` was raised. Thanks to [Jacob
10
+ Green](https://github.com/Jacobkg) for helping to troubleshoot
11
+ this bug!
12
+
5
13
  ## 2.2.2 (June 15, 2012)
6
14
 
7
15
  [Full Changelog](http://github.com/myronmarston/vcr/compare/v2.2.1...v2.2.2)
data/README.md CHANGED
@@ -106,7 +106,8 @@ Note that as of VCR 2, 1.8.6 and 1.9.1 are not supported.
106
106
  ## Development
107
107
 
108
108
  * Source hosted on [GitHub](http://github.com/myronmarston/vcr).
109
- * Direct questions and discussions to the [mailing list](http://groups.google.com/group/vcr-ruby).
109
+ * Direct questions and discussions to the [IRC channel](irc://irc.freenode.net/vcr) or
110
+ the [mailing list](http://groups.google.com/group/vcr-ruby).
110
111
  * Report issues on [GitHub Issues](http://github.com/myronmarston/vcr/issues).
111
112
  * Pull requests are very welcome! Please include spec and/or feature coverage for every patch,
112
113
  and create a topic branch for every separate change you make.
@@ -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.13').check_version!
5
+ VCR::VersionChecker.new('Excon', Excon::VERSION, '0.9.6', '0.14').check_version!
6
6
 
7
7
  module VCR
8
8
  class LibraryHooks
@@ -17,13 +17,7 @@ module VCR
17
17
  def initialize(net_http, request, request_body = nil, &response_block)
18
18
  @net_http, @request, @request_body, @response_block =
19
19
  net_http, request, request_body, response_block
20
- @vcr_response, @recursing = nil, false
21
-
22
- if ([:@__vcr_request_type, "@__vcr_request_type"] & request.instance_variables).any?
23
- @request_type = request.instance_variable_get(:@__vcr_request_type)
24
- else
25
- @request_type = nil
26
- end
20
+ @stubbed_response, @vcr_response, @recursing = nil, nil, false
27
21
  end
28
22
 
29
23
  def handle
@@ -32,42 +26,12 @@ module VCR
32
26
  invoke_after_request_hook(@vcr_response) unless @recursing
33
27
  end
34
28
 
35
- class << self
36
- def already_seen_requests
37
- @already_seen_requests ||= Set.new
38
- end
39
- end
40
-
41
29
  private
42
30
 
43
31
  def externally_stubbed?
44
32
  ::FakeWeb.registered_uri?(request_method, uri)
45
33
  end
46
34
 
47
- def request_type(*args)
48
- @request_type || super
49
- end
50
-
51
- def set_typed_request_for_after_hook(request_type)
52
- @request.instance_variable_set(:@__vcr_request_type, request_type)
53
- super
54
- end
55
-
56
- def invoke_before_request_hook
57
- unless self.class.already_seen_requests.include?(request.object_id)
58
- super
59
- # we use the object_id so that if there is bug that causes
60
- # us not to fully cleanup, we'll only be leaking the memory
61
- # of one integer, not the whole request object.
62
- self.class.already_seen_requests << request.object_id
63
- end
64
- end
65
-
66
- def invoke_after_request_hook(vcr_response)
67
- self.class.already_seen_requests.delete(request.object_id)
68
- super
69
- end
70
-
71
35
  def on_externally_stubbed_request
72
36
  # just perform the request--FakeWeb will handle it
73
37
  perform_request(:started)
@@ -95,6 +59,7 @@ module VCR
95
59
  # that is the final time through #request.
96
60
  unless started
97
61
  @recursing = true
62
+ request.instance_variable_set(:@__vcr_request_handler, recursive_request_handler)
98
63
  return net_http.request_without_vcr(request, request_body, &response_block)
99
64
  end
100
65
 
@@ -152,6 +117,34 @@ module VCR
152
117
  response.body,
153
118
  response.http_version
154
119
  end
120
+
121
+ def recursive_request_handler
122
+ @recursive_request_handler ||= RecursiveRequestHandler.new(
123
+ @after_hook_typed_request.type, @stubbed_response, @vcr_request,
124
+ @net_http, @request, @request_body, &@response_block
125
+ )
126
+ end
127
+ end
128
+
129
+ class RecursiveRequestHandler < RequestHandler
130
+ attr_reader :stubbed_response
131
+
132
+ def initialize(request_type, stubbed_response, vcr_request, *args, &response_block)
133
+ @request_type, @stubbed_response, @vcr_request =
134
+ request_type, stubbed_response, vcr_request
135
+ super(*args)
136
+ end
137
+
138
+ def handle
139
+ set_typed_request_for_after_hook(@request_type)
140
+ send "on_#{@request_type}_request"
141
+ ensure
142
+ invoke_after_request_hook(@vcr_response)
143
+ end
144
+
145
+ def request_type(*args)
146
+ @request_type
147
+ end
155
148
  end
156
149
  end
157
150
  end
@@ -162,13 +155,15 @@ module Net
162
155
  # @private
163
156
  class HTTP
164
157
  unless method_defined?(:request_with_vcr)
165
- def request_with_vcr(*args, &block)
158
+ def request_with_vcr(request, *args, &block)
166
159
  if VCR.turned_on?
167
- VCR::LibraryHooks::FakeWeb::RequestHandler.new(
168
- self, *args, &block
169
- ).handle
160
+ handler = request.instance_eval do
161
+ remove_instance_variable(:@__vcr_request_handler) if defined?(@__vcr_request_handler)
162
+ end || VCR::LibraryHooks::FakeWeb::RequestHandler.new(self, request, *args, &block)
163
+
164
+ handler.handle
170
165
  else
171
- request_without_vcr(*args, &block)
166
+ request_without_vcr(request, *args, &block)
172
167
  end
173
168
  end
174
169
 
@@ -15,10 +15,10 @@ module VCR
15
15
  # (i.e. by inserting a cassette), so we need to query the
16
16
  # request type again.
17
17
  #
18
- # Likewise, the main handler logic an modify what
18
+ # Likewise, the main handler logic can modify what
19
19
  # #request_type would return (i.e. when a response stub is
20
20
  # used), so we need to store the request type for the
21
- # the after_request hook.
21
+ # after_request hook.
22
22
  set_typed_request_for_after_hook(req_type)
23
23
 
24
24
  send "on_#{req_type}_request"
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.2'
13
+ string = '2.2.3'
14
14
 
15
15
  def string.parts
16
16
  split('.').map { |p| p.to_i }
@@ -14,6 +14,14 @@ RSpec.configure do |config|
14
14
 
15
15
  vcr_warnings, other_warnings = lines.partition { |line| line.include?(current_dir) }
16
16
 
17
+ # After upgrading to curb 0.8.1, I started to get a circular require
18
+ # warning from spec_helper and monkey_patches.rb even though there doesn't
19
+ # appear to be a circular require going on...
20
+ vcr_warnings.reject! do |line|
21
+ line.include?("#{current_dir}/spec/spec_helper.rb") ||
22
+ line.include?("#{current_dir}/spec/monkey_patches.rb")
23
+ end
24
+
17
25
  # For some weird reason, JRuby is giving me some warnings about
18
26
  # `@proxy` not being initialized, and putting a vcr file/line number
19
27
  # in the warning, but it's really happening in excon.
@@ -25,7 +25,7 @@ describe VCR::Net::HTTPResponse do
25
25
 
26
26
  it 'raises an ArgumentError if both a destination string and a block is given to #read_body' do
27
27
  dest = ''
28
- expect { response { |r| r.read_body(dest) { |s| } } }.should raise_error(ArgumentError, 'both arg and block given for HTTP method')
28
+ expect { response { |r| r.read_body(dest) { |s| } } }.to raise_error(ArgumentError, 'both arg and block given for HTTP method')
29
29
  end
30
30
 
31
31
  it 'raises an IOError when #read_body is called twice with a block' do
@@ -18,16 +18,7 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
18
18
  ::FakeWeb.register_uri(method, url, :body => response_body)
19
19
  end
20
20
 
21
- it_behaves_like 'a hook into an HTTP library', :fakeweb, 'net/http' do
22
- before(:each) do
23
- VCR::LibraryHooks::FakeWeb::RequestHandler.already_seen_requests.clear
24
- end
25
-
26
- after(:each) do
27
- # assert that we are cleaning up the global state after every request
28
- VCR::LibraryHooks::FakeWeb::RequestHandler.already_seen_requests.to_a.should eq([])
29
- end
30
- end
21
+ it_behaves_like 'a hook into an HTTP library', :fakeweb, 'net/http'
31
22
 
32
23
  describe "some specific Net::HTTP edge cases" do
33
24
  before(:each) do
@@ -95,6 +86,24 @@ describe "FakeWeb hook", :with_monkey_patches => :fakeweb do
95
86
  ignored_body.should_not eq(recorded_body)
96
87
  ignored_body.should match(/Response \d+/)
97
88
  end
89
+
90
+ context 'when the same Net::HTTP request object is used twice' do
91
+ let(:uri) { URI("http://localhost:#{VCR::SinatraApp.port}/foo") }
92
+ let(:http) { Net::HTTP.new(uri.host, uri.port) }
93
+
94
+ it 'raises an UnhandledHTTPRequestError when using a cassette that only recorded one request' do
95
+ VCR.use_cassette("new_cassette", :record => :once) do
96
+ request = Net::HTTP::Get.new(uri.request_uri)
97
+ http.request(request)
98
+ end
99
+
100
+ VCR.use_cassette("new_cassette", :record => :once) do
101
+ request = Net::HTTP::Get.new(uri.request_uri)
102
+ http.request(request)
103
+ http.request(request)
104
+ end
105
+ end
106
+ end
98
107
  end
99
108
 
100
109
  describe "VCR.configuration.after_library_hooks_loaded hook" do
@@ -1,10 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.configure do |config|
4
- config.before(:suite) do
5
- VCR.configuration.configure_rspec_metadata!
6
- end
7
- end
3
+ VCR.configuration.configure_rspec_metadata!
8
4
 
9
5
  describe VCR::RSpec::Metadata, :skip_vcr_reset do
10
6
  before(:all) { VCR.reset! }
data/vcr.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
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.9.0'
26
+ s.add_development_dependency 'rspec', '~> 2.11'
27
27
  s.add_development_dependency 'shoulda', '~> 2.9.2'
28
28
 
29
29
  s.add_development_dependency 'fakeweb', '~> 1.3.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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 2
10
- version: 2.2.2
9
+ - 3
10
+ version: 2.2.3
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-06-15 00:00:00 Z
18
+ date: 2012-07-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -87,12 +87,11 @@ dependencies:
87
87
  requirements:
88
88
  - - ~>
89
89
  - !ruby/object:Gem::Version
90
- hash: 43
90
+ hash: 21
91
91
  segments:
92
92
  - 2
93
- - 9
94
- - 0
95
- version: 2.9.0
93
+ - 11
94
+ version: "2.11"
96
95
  name: rspec
97
96
  type: :development
98
97
  prerelease: false