Skip to content
Browse files

Gracefully handle a faraday stack w/ no explicit adapter.

Closes #170.
  • Loading branch information...
1 parent 04cd243 commit 30549e80b0876d8d90cce24a5330942d3c965703 @myronmarston committed May 22, 2012
Showing with 19 additions and 1 deletion.
  1. +3 −0 CHANGELOG.md
  2. +2 −1 lib/vcr/library_hooks/faraday.rb
  3. +14 −0 spec/vcr/library_hooks/faraday_spec.rb
View
3 CHANGELOG.md
@@ -22,6 +22,9 @@
providing a fix.
* Fix `filter_sensitive_data`/`define_cassette_placeholder` so that they
handle non-strings gracefully (e.g. the port number as a Fixnum).
+* Gracefully handle Faraday connection stacks that do not explicitly
+ specify an HTTP adapter. Thanks to [Patrick Roby](https://github.com/proby)
+ for reporting the bug.
## 2.1.1 (April 24, 2012)
View
3 lib/vcr/library_hooks/faraday.rb
@@ -25,13 +25,14 @@ def lock!(*args)
def insert_vcr_middleware
return if handlers.any? { |h| h.klass == VCR::Middleware::Faraday }
adapter_index = handlers.index { |h| h.klass < ::Faraday::Adapter }
+ adapter_index ||= handlers.size
warn_about_after_adapter_middleware(adapter_index)
insert_before(adapter_index, VCR::Middleware::Faraday)
end
def warn_about_after_adapter_middleware(adapter_index)
after_adapter_middleware_count = (handlers.size - adapter_index - 1)
- return if after_adapter_middleware_count.zero?
+ return if after_adapter_middleware_count < 1
after_adapter_middlewares = handlers.last(after_adapter_middleware_count)
warn "WARNING: The Faraday connection stack contains middleware after " +
View
14 spec/vcr/library_hooks/faraday_spec.rb
@@ -50,5 +50,19 @@
conn.builder.should_receive(:warn).with(/Faraday::Response::Logger/)
conn.builder.lock!
end
+
+ it 'gracefully handles the case where there is no explicit HTTP adapter' do
+ conn = Faraday.new(:url => 'http://sushi.com') do |builder|
+ builder.request :url_encoded
+ builder.response :logger
+ end
+
+ conn.builder.lock!
+ conn.builder.handlers.map(&:klass).should eq([
+ Faraday::Request::UrlEncoded,
+ Faraday::Response::Logger,
+ VCR::Middleware::Faraday
+ ])
+ end
end

0 comments on commit 30549e8

Please sign in to comment.
Something went wrong with that request. Please try again.