mirror of
https://github.com/lostisland/faraday.git
synced 2025-12-08 00:02:54 -05:00
dont require typhoeus for tests
This commit is contained in:
parent
ba8632bcd0
commit
75bec559d6
@ -44,12 +44,12 @@ the API on a whim.
|
||||
|
||||
== Testing
|
||||
|
||||
* Typhoeus and Yajl are needed for tests :(
|
||||
* Yajl are needed for tests :(
|
||||
* Live Sinatra server is required for tests: `ruby test/live_server.rb` to start it.
|
||||
|
||||
== TODO
|
||||
|
||||
* gracefully skip tests for Typhoeus, Yajl, and other optional libraries if they don't exist.
|
||||
* gracefully skip tests for Yajl and other optional libraries if they don't exist.
|
||||
* gracefully skip live http server tests if the sinatra server is not running.
|
||||
* lots of other crap
|
||||
|
||||
|
||||
@ -13,6 +13,14 @@ module Faraday
|
||||
module Adapter
|
||||
autoload :NetHttp, 'faraday/adapter/net_http'
|
||||
autoload :Typhoeus, 'faraday/adapter/typhoeus'
|
||||
|
||||
def self.adapters
|
||||
constants
|
||||
end
|
||||
|
||||
def self.loaded_adapters
|
||||
adapters.map { |c| const_get(c) }.select { |a| a.loaded }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -2,6 +2,8 @@ require 'net/http'
|
||||
module Faraday
|
||||
module Adapter
|
||||
module NetHttp
|
||||
def self.loaded() true end
|
||||
|
||||
def _get(uri, request_headers)
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
response_class.new do |resp|
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
require 'typhoeus'
|
||||
|
||||
module Faraday
|
||||
module Adapter
|
||||
module Typhoeus
|
||||
class << self
|
||||
attr_accessor :loaded
|
||||
end
|
||||
|
||||
begin
|
||||
require 'typhoeus'
|
||||
self.loaded = true
|
||||
|
||||
def in_parallel?
|
||||
!!@parallel_manager
|
||||
end
|
||||
@ -42,6 +50,8 @@ module Faraday
|
||||
map! { |(k, v)| [k.downcase, v] }.
|
||||
tap { |a| a.flatten! }]
|
||||
end
|
||||
rescue LoadError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
|
||||
|
||||
class TyphoeusTest < Faraday::TestCase
|
||||
if Faraday::Adapter::Typhoeus.loaded
|
||||
class TyphoeusTest < Faraday::TestCase
|
||||
describe "#parse_response_headers" do
|
||||
before do
|
||||
@conn = Object.new.extend(Faraday::Adapter::Typhoeus)
|
||||
@ -21,4 +22,5 @@ class TyphoeusTest < Faraday::TestCase
|
||||
assert_equal 'http://sushi.com/', headers['location']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -5,7 +5,7 @@ class AdapterTest < Faraday::TestCase
|
||||
@connection = Faraday::Connection.new(LIVE_SERVER)
|
||||
end
|
||||
|
||||
[Faraday::Adapter::NetHttp, Faraday::Adapter::Typhoeus].each do |adapter|
|
||||
Faraday::Adapter.loaded_adapters.each do |adapter|
|
||||
describe "#get with #{adapter} adapter" do
|
||||
before do
|
||||
@connection.extend adapter
|
||||
@ -26,6 +26,7 @@ class AdapterTest < Faraday::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
if Faraday::Adapter::Typhoeus.loaded
|
||||
describe "async Typhoeus requests" do
|
||||
before do
|
||||
@connection.extend Faraday::Adapter::Typhoeus
|
||||
@ -54,4 +55,5 @@ class AdapterTest < Faraday::TestCase
|
||||
assert_equal [1,2,3], resp2.body
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
require 'rubygems'
|
||||
require 'context'
|
||||
if ENV['LEFTRIGHT']
|
||||
require 'leftright'
|
||||
end
|
||||
|
||||
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user