Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 16 commits
  • 11 files changed
  • 0 comments
  • 3 contributors
5  .travis.yml
... ...
@@ -1,11 +1,6 @@
1 1
 script: "bundle exec rake ci:build"
2 2
 rvm:
3  
-  - 1.8.6
4 3
   - 1.8.7
5  
-  - 1.9.1
6 4
   - 1.9.2
7  
-  - ree
8  
-  - jruby
9  
-  - rbx
10 5
 env:
11 6
   - CI=true
13  CHANGELOG.md
Source Rendered
... ...
@@ -1,6 +1,17 @@
1 1
 ## In git
2 2
 
3  
-[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.10.0...master)
  3
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.10.1...master)
  4
+
  5
+## 1.10.1 (July 16, 2011)
  6
+
  7
+[Full Changelog](http://github.com/myronmarston/vcr/compare/v1.10.0...v1.10.1)
  8
+
  9
+* Fix typo in error message [Bradley](https://github.com/bradleyisotope).
  10
+* Fix excon adapter to properly handle queries specified as a hash.
  11
+* Fix excon adapter to stub a response with a hash as excon expects
  12
+  [Wesley Beary](https://github.com/geemus).
  13
+* Fix excon adapter so that it records a response even when excon raises
  14
+  an error due to an unexpected response.
4 15
 
5 16
 ## 1.10.0 (May 18, 2011)
6 17
 
8  Rakefile
@@ -70,11 +70,15 @@ task :relish do
70 70
   end
71 71
 
72 72
   require 'vcr/version'
73  
-  sh "relish versions:add myronmarston/vcr:#{VCR.version}"
  73
+  sh "relish versions:add myronmarston/vcr:#{VCR.version}" if ENV['NEW_RELISH_RELEASE']
74 74
   sh "relish push vcr:#{VCR.version}"
75 75
 end
76 76
 
77  
-task :release => :relish
  77
+task :prep_relish_release do
  78
+  ENV['NEW_RELISH_RELEASE'] = 'true'
  79
+end
  80
+
  81
+task :release => [:prep_relish_release, :relish]
78 82
 
79 83
 # For gem-test: http://gem-testers.org/
80 84
 task :test => :spec
2  features/configuration/filter_sensitive_data.feature
@@ -2,7 +2,7 @@ Feature: Filter sensitive data
2 2
 
3 3
   The `filter_sensitive_data` configuration option can be used to prevent
4 4
   sensitive data from being written to your cassette files.  This may be
5  
-  important if you commit your cassettes files to source controla and do
  5
+  important if you commit your cassettes files to source control and do
6 6
   not want your sensitive data exposed.  Pass the following arguments to
7 7
   `filter_sensitive_data`:
8 8
 
2  features/http_libraries/net_http.feature
@@ -146,7 +146,7 @@ Feature: Net::HTTP
146 146
           c.cassette_library_dir = 'cassettes'
147 147
         end
148 148
 
149  
-        uri = URI("https://gist.github.com/raw/fb555cb593f3349d53af/6921dd638337d3f6a51b0e02e7f30e3c414f70d6/vcr_gist")
  149
+        uri = URI("https://raw.github.com/gist/fb555cb593f3349d53af/6921dd638337d3f6a51b0e02e7f30e3c414f70d6/vcr_gist")
150 150
 
151 151
         VCR.use_cassette('https', :record => :new_episodes) do
152 152
           http = Net::HTTP.new(uri.host, uri.port)
2  lib/vcr.rb
@@ -58,7 +58,7 @@ def insert_cassette(name, options = {})
58 58
       cassette
59 59
     elsif !ignore_cassettes?
60 60
       message = "VCR is turned off.  You must turn it on before you can insert a cassette.  " +
61  
-                "Or you can use the `:ignore_cassette => true` option to completely ignore cassette insertions."
  61
+                "Or you can use the `:ignore_cassettes => true` option to completely ignore cassette insertions."
62 62
       raise TurnedOffError.new(message)
63 63
     end
64 64
   end
59  lib/vcr/http_stubbing_adapters/excon.rb
@@ -8,7 +8,7 @@ module Excon
8 8
 
9 9
       class HttpConnectionNotAllowedError < StandardError; end
10 10
 
11  
-      MINIMUM_VERSION = '0.6.2'
  11
+      MINIMUM_VERSION = '0.6.5'
12 12
       MAXIMUM_VERSION = '0.6'
13 13
 
14 14
       attr_writer :http_connections_allowed
@@ -119,24 +119,40 @@ def request_should_be_ignored?
119 119
           end
120 120
 
121 121
           def stubbed_response
122  
-            unless defined?(@stubbed_response)
123  
-              @stubbed_response = VCR::HttpStubbingAdapters::Excon.stubbed_response_for(vcr_request)
124  
-
125  
-              if @stubbed_response && @stubbed_response.headers
126  
-                @stubbed_response.headers = normalized_headers(@stubbed_response.headers)
  122
+            @stubbed_response ||= begin
  123
+              if stubbed_response = VCR::HttpStubbingAdapters::Excon.stubbed_response_for(vcr_request)
  124
+                {
  125
+                  :body     => stubbed_response.body,
  126
+                  :headers  => normalized_headers(stubbed_response.headers || {}),
  127
+                  :status   => stubbed_response.status.code
  128
+                }
127 129
               end
128 130
             end
129  
-
130  
-            @stubbed_response
131 131
           end
132 132
 
133 133
           def http_connections_allowed?
134 134
             VCR::HttpStubbingAdapters::Excon.http_connections_allowed?
135 135
           end
136 136
 
  137
+          def response_from_excon_error(error)
  138
+            if error.respond_to?(:response)
  139
+              error.response
  140
+            elsif error.respond_to?(:socket_error)
  141
+              response_from_excon_error(error.socket_error)
  142
+            else
  143
+              warn "WARNING: VCR could not extract a response from Excon error (#{error.inspect})"
  144
+            end
  145
+          end
  146
+
137 147
           def perform_real_request
138 148
             connection = ::Excon.new(uri)
139  
-            response = connection.request(params.merge(:mock => false))
  149
+
  150
+            response = begin
  151
+              connection.request(params.merge(:mock => false))
  152
+            rescue ::Excon::Errors::Error => e
  153
+              yield response_from_excon_error(e) if block_given?
  154
+              raise e
  155
+            end
140 156
 
141 157
             yield response if block_given?
142 158
 
@@ -153,10 +169,27 @@ def record_interaction
153 169
           end
154 170
 
155 171
           def uri
156  
-            @uri ||= begin
157  
-              uri = "#{params[:scheme]}://#{params[:host]}:#{params[:port]}#{params[:path]}"
158  
-              uri << "?#{params[:query]}" if params[:query]
159  
-              uri
  172
+            @uri ||= "#{params[:scheme]}://#{params[:host]}:#{params[:port]}#{params[:path]}#{query}"
  173
+          end
  174
+
  175
+          def query
  176
+            @query ||= case params[:query]
  177
+              when String
  178
+                "?#{params[:query]}"
  179
+              when Hash
  180
+                qry = '?'
  181
+                for key, values in params[:query]
  182
+                  if values.nil?
  183
+                    qry << key.to_s << '&'
  184
+                  else
  185
+                    for value in [*values]
  186
+                      qry << key.to_s << '=' << CGI.escape(value.to_s) << '&'
  187
+                    end
  188
+                  end
  189
+                end
  190
+                qry.chop! # remove trailing '&'
  191
+              else
  192
+                ''
160 193
             end
161 194
           end
162 195
 
2  lib/vcr/version.rb
@@ -3,7 +3,7 @@ module VCR
3 3
 
4 4
   def version
5 5
     @version ||= begin
6  
-      string = '1.10.0'
  6
+      string = '1.10.1'
7 7
 
8 8
       def string.parts
9 9
         split('.').map { |p| p.to_i }
4  spec/support/sinatra_app.rb
@@ -6,6 +6,10 @@ class SinatraApp < ::Sinatra::Base
6 6
       "GET to root"
7 7
     end
8 8
 
  9
+    get '/search' do
  10
+      "query: #{params[:q]}"
  11
+    end
  12
+
9 13
     get '/localhost_test' do
10 14
       "Localhost response"
11 15
     end
54  spec/vcr/http_stubbing_adapters/excon_spec.rb
@@ -7,8 +7,8 @@
7 7
     :status_message_not_exposed
8 8
 
9 9
   it_performs('version checking',
10  
-    :valid    => %w[ 0.6.2 0.6.99 ],
11  
-    :too_low  => %w[ 0.5.99 0.6.1 ],
  10
+    :valid    => %w[ 0.6.5 0.6.99 ],
  11
+    :too_low  => %w[ 0.5.99 0.6.4 ],
12 12
     :too_high => %w[ 0.7.0 1.0.0 ]
13 13
   ) do
14 14
     before(:each) { @orig_version = Excon::VERSION }
@@ -19,5 +19,55 @@
19 19
       Excon::VERSION = version
20 20
     end
21 21
   end
  22
+
  23
+  context "when the query is specified as a hash option" do
  24
+    let(:excon) { ::Excon.new("http://localhost:#{VCR::SinatraApp.port}/search") }
  25
+
  26
+    it 'properly records and plays back the response' do
  27
+      described_class.http_connections_allowed = true
  28
+      recorded, played_back = [1, 2].map do
  29
+        VCR.use_cassette('excon_query', :record => :once) do
  30
+          excon.request(:method => :get, :query => { :q => 'Tolkien' }).body
  31
+        end
  32
+      end
  33
+
  34
+      recorded.should == played_back
  35
+      recorded.should == 'query: Tolkien'
  36
+    end
  37
+  end
  38
+
  39
+  context "when Excon's streaming API is used" do
  40
+    it 'properly records and plays back the response' do
  41
+      described_class.http_connections_allowed = true
  42
+      recorded, played_back = [1, 2].map do
  43
+        chunks = []
  44
+
  45
+        VCR.use_cassette('excon_streaming', :record => :once) do
  46
+          Excon.get("http://localhost:#{VCR::SinatraApp.port}/foo") do |chunk, remaining_bytes, total_bytes|
  47
+            chunks << chunk
  48
+          end
  49
+        end
  50
+
  51
+        chunks.join
  52
+      end
  53
+
  54
+      recorded.should == played_back
  55
+      recorded.should == "FOO!"
  56
+    end
  57
+  end
  58
+
  59
+  context 'when Excon raises an error due to an unexpected response status' do
  60
+    it 'still records properly' do
  61
+      described_class.http_connections_allowed = true
  62
+
  63
+      VCR.should_receive(:record_http_interaction) do |interaction|
  64
+        interaction.response.status.code.should == 404
  65
+      end
  66
+
  67
+      expect {
  68
+        Excon.get("http://localhost:#{VCR::SinatraApp.port}/not_found", :expects => 200)
  69
+      }.to raise_error(Excon::Errors::Error)
  70
+    end
  71
+  end
22 72
 end
23 73
 
4  vcr.gemspec
@@ -30,9 +30,9 @@ Gem::Specification.new do |s|
30 30
     'webmock'         => '~> 1.6.4',
31 31
     'addressable'     => '~> 2.2.6',
32 32
 
33  
-    'faraday'         => '~> 0.6.0',
  33
+    'faraday'         => '~> 0.7.2',
34 34
     'httpclient'      => '~> 2.1.5.2',
35  
-    'excon'           => '~> 0.6.2',
  35
+    'excon'           => '~> 0.6.5',
36 36
 
37 37
     'timecop'         => '~> 0.3.5',
38 38
     'rack'            => '1.1.0',

No commit comments for this range

Something went wrong with that request. Please try again.