properly skip adapter tests if LIVE env variable isn't configured

This commit is contained in:
Mislav Marohnić 2012-04-14 18:42:18 +02:00
parent 7ecb7fa211
commit 9c49b0b4c4
10 changed files with 83 additions and 83 deletions

View File

@ -2,11 +2,13 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class DefaultTest < Faraday::TestCase
include Integration
include Integration::NonParallel
def adapter; :default end
def adapter() :default end
Integration.apply(self, :NonParallel) do
# default stack is not configured with Multipart
undef :test_POST_sends_files
end
undef :test_POST_sends_files
end
end

View File

@ -2,12 +2,13 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class EMHttpTest < Faraday::TestCase
include Integration
include Integration::Parallel
def adapter; :em_http end
def adapter() :em_http end
Integration.apply(self, :Parallel) do
# https://github.com/eventmachine/eventmachine/pull/289
undef :test_timeout
end
# https://github.com/eventmachine/eventmachine/pull/289
undef :test_timeout
end
end
end

View File

@ -2,12 +2,13 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class EMSynchronyTest < Faraday::TestCase
include Integration
include Integration::Parallel
def adapter; :em_synchrony end
def adapter() :em_synchrony end
Integration.apply(self, :Parallel) do
# https://github.com/eventmachine/eventmachine/pull/289
undef :test_timeout
end
# https://github.com/eventmachine/eventmachine/pull/289
undef :test_timeout
end
end

View File

@ -2,15 +2,18 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class ExconTest < Faraday::TestCase
def adapter() :excon end
# https://github.com/geemus/excon/issues/98
if defined?(RUBY_ENGINE) && "rbx" != RUBY_ENGINE
include Integration
include Integration::NonParallel
def adapter; :excon end
# https://github.com/eventmachine/eventmachine/pull/289
undef :test_timeout
if defined?(RUBY_ENGINE) and "rbx" == RUBY_ENGINE
warn "Warning: Skipping Excon tests on Rubinius"
else
Integration.apply(self, :NonParallel) do
# https://github.com/eventmachine/eventmachine/pull/289
undef :test_timeout
end
end
end
end

View File

@ -6,47 +6,48 @@ module Adapters
# `#adapter` required. returns a symbol for the adapter middleware name
# `#adapter_options` optional. extra arguments for building an adapter
module Integration
def self.included(base)
def self.apply(base, *extras)
if Faraday::TestCase::LIVE_SERVER
base.send(:include, Common)
([:Common] + extras).each {|name| base.send(:include, self.const_get(name)) }
yield if block_given?
elsif !defined? @warned
warn "Warning: Not running integration tests against a live server."
warn "Start the server `ruby test/live_server.rb` and set the LIVE=1 env variable."
@warned = true
end
end
module Parallel
if Faraday::TestCase::LIVE_SERVER
def test_in_parallel
resp1, resp2 = nil, nil
def test_in_parallel
resp1, resp2 = nil, nil
connection = create_connection(adapter)
connection.in_parallel do
resp1 = connection.get('echo?a=1')
resp2 = connection.get('echo?b=2')
assert connection.in_parallel?
assert_nil resp1.body
assert_nil resp2.body
end
assert !connection.in_parallel?
assert_equal 'get ?{"a"=>"1"}', resp1.body
assert_equal 'get ?{"b"=>"2"}', resp2.body
connection = create_connection(adapter)
connection.in_parallel do
resp1 = connection.get('echo?a=1')
resp2 = connection.get('echo?b=2')
assert connection.in_parallel?
assert_nil resp1.body
assert_nil resp2.body
end
assert !connection.in_parallel?
assert_equal 'get ?{"a"=>"1"}', resp1.body
assert_equal 'get ?{"b"=>"2"}', resp2.body
end
end
module NonParallel
if Faraday::TestCase::LIVE_SERVER
def test_no_parallel_support
connection = create_connection(adapter)
response = nil
def test_no_parallel_support
connection = create_connection(adapter)
response = nil
err = capture_warnings do
connection.in_parallel do
response = connection.get('echo').body
end
err = capture_warnings do
connection.in_parallel do
response = connection.get('echo').body
end
assert response
assert_match "no parallel-capable adapter on Faraday stack", err
assert_match __FILE__, err
end
assert response
assert_match "no parallel-capable adapter on Faraday stack", err
assert_match __FILE__, err
end
end
@ -196,4 +197,4 @@ module Adapters
end
end
end
end
end

View File

@ -2,9 +2,10 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class NetHttpPersistentTest < Faraday::TestCase
include Integration
include Integration::NonParallel
def adapter; :net_http_persistent end
def adapter() :net_http_persistent end
Integration.apply(self, :NonParallel)
end
end
end

View File

@ -2,10 +2,10 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class NetHttpTest < Faraday::TestCase
include Integration
include Integration::NonParallel
def adapter; :net_http end
def adapter() :net_http end
Integration.apply(self, :NonParallel)
def setup
@connection = Faraday.new('http://disney.com') do |b|

View File

@ -2,20 +2,16 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class Patron < Faraday::TestCase
include Integration
include Integration::NonParallel
def adapter; :patron end
def adapter() :patron end
# https://github.com/toland/patron/issues/34
undef :test_PATCH_send_url_encoded_params
Integration.apply(self, :NonParallel) do
# https://github.com/toland/patron/issues/34
undef :test_PATCH_send_url_encoded_params
# https://github.com/toland/patron/issues/9
undef :test_PUT_retrieves_the_response_headers
undef :test_PUT_send_url_encoded_params
undef :test_PUT_send_url_encoded_nested_params
# https://github.com/toland/patron/issues/52
undef :test_GET_with_body
end
# https://github.com/toland/patron/issues/52
undef :test_GET_with_body
end
end

View File

@ -3,17 +3,15 @@ require File.expand_path('../../live_server', __FILE__)
module Adapters
class RackTest < Faraday::TestCase
include Integration
include Integration::NonParallel
def adapter
:rack
end
def adapter() :rack end
def adapter_options
Sinatra::Application
end
Integration.apply(self, :NonParallel)
# not using Integration::Timeout because error is swallowed by sinatra
def test_timeout
conn = create_connection(adapter, :request => {:timeout => 1, :open_timeout => 1})
@ -27,4 +25,4 @@ module Adapters
assert false, "did not timeout"
end
end
end
end

View File

@ -2,16 +2,13 @@ require File.expand_path('../integration', __FILE__)
module Adapters
class TyphoeusTest < Faraday::TestCase
include Integration
include Integration::Parallel
def adapter; :typhoeus end
def adapter() :typhoeus end
# https://github.com/dbalatero/typhoeus/issues/84
undef :test_PUT_retrieves_the_response_headers
# https://github.com/dbalatero/typhoeus/issues/75
undef :test_GET_with_body
Integration.apply(self, :Parallel) do
# https://github.com/dbalatero/typhoeus/issues/75
undef :test_GET_with_body
end
def setup
@connection = Faraday.new('http://disney.com') do |b|