Skip to content
Browse files

Removed Typhoeus::Easy support

  • Loading branch information...
1 parent c2a25b4 commit fe52257cd0105badcb808634d8bc9b851487381e @bblimke committed Aug 9, 2011
Showing with 0 additions and 220 deletions.
  1. +0 −2 lib/webmock.rb
  2. +0 −98 lib/webmock/http_lib_adapters/typhoeus_easy.rb
  3. +0 −73 spec/typhoeus_easy_spec.rb
  4. +0 −47 spec/typhoeus_easy_spec_helper.rb
View
2 lib/webmock.rb
@@ -12,8 +12,6 @@
require 'webmock/http_lib_adapters/curb'
require 'webmock/http_lib_adapters/em_http_request'
require 'webmock/http_lib_adapters/typhoeus_hydra'
-require 'webmock/http_lib_adapters/typhoeus_easy'
-
require 'webmock/errors'
View
98 lib/webmock/http_lib_adapters/typhoeus_easy.rb
@@ -1,98 +0,0 @@
-if defined?(Typhoeus)
- module Typhoeus
- class Easy
- def build_request_signature
- uri = WebMock::Util::URI.heuristic_parse(self.url)
- uri.path = uri.normalized_path.gsub("[^:]//","/")
- if @webmock_auth
- uri.user = @webmock_auth[:username]
- uri.password = @webmock_auth[:password]
- end
-
- request_signature = WebMock::RequestSignature.new(
- @method,
- uri.to_s,
- :body => @request_body,
- :headers => @headers
- )
- request_signature
- end
-
- def build_webmock_response
- response = Typhoeus::Response.new(:headers => self.response_header)
- webmock_response = WebMock::Response.new
- webmock_response.status = [self.response_code, response.status_message]
- webmock_response.body = self.response_body
- webmock_response.headers = WebMock::Util::Headers.normalize_headers(response.headers_hash)
- webmock_response
- end
-
- def build_easy_response(webmock_response)
- raise Curl::Err::TimeoutError if webmock_response.should_timeout
- webmock_response.raise_error_if_any
- @response_body = webmock_response.body
- @webmock_response_code = webmock_response.status[0].to_i
-
- @response_header = "HTTP/1.1 #{webmock_response.status[0]} #{webmock_response.status[1]}\r\n"
- if webmock_response.headers
- @response_header << webmock_response.headers.map do |k,v|
- "#{k}: #{v.is_a?(Array) ? v.join(", ") : v}"
- end.join("\r\n")
- end
- end
-
- def auth_with_webmock=(auth)
- @webmock_auth = auth
- auth_without_webmock=(auth)
- end
- alias :auth_without_webmock= :auth=
- alias :auth= :auth_with_webmock=
-
- def response_code_with_webmock
- if @webmock_response_code
- @webmock_response_code
- else
- response_code_without_webmock
- end
- end
- alias :response_code_without_webmock :response_code
- alias :response_code :response_code_with_webmock
-
- def reset_with_webmock
- @webmock_auth = nil
- reset_without_webmock
- end
- alias :reset_without_webmock :reset
- alias :reset :reset_with_webmock
-
- def easy_perform_with_webmock
- @webmock_response_code = nil
- request_signature = build_request_signature
- WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
- if WebMock::StubRegistry.instance.registered_request?(request_signature)
- webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
- build_easy_response(webmock_response)
- WebMock::CallbackRegistry.invoke_callbacks(
- {:lib => :typhoeus}, request_signature, webmock_response)
- # invoke_easy_callbacks
- true
- elsif WebMock.net_connect_allowed?(request_signature.uri)
- res = easy_perform_without_webmock
- if WebMock::CallbackRegistry.any_callbacks?
- webmock_response = build_webmock_response
- WebMock::CallbackRegistry.invoke_callbacks(
- {:lib => :typhoeus, :real_request => true}, request_signature,
- webmock_response)
- end
- res
- else
- raise WebMock::NetConnectNotAllowedError.new(request_signature)
- end
- end
- alias :easy_perform_without_webmock :easy_perform
- alias :easy_perform :easy_perform_with_webmock
- end
-
-
- end
-end
View
73 spec/typhoeus_easy_spec.rb
@@ -1,73 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-require 'webmock_shared'
-
-unless RUBY_PLATFORM =~ /java/
- require 'typhoeus_easy_spec_helper'
-
- describe "Webmock with Typhoeus::Easy" do
- include TyphoeusEasySpecHelper
-
- it_should_behave_like "WebMock"
-
- describe "Typhoeus::Easy features" do
- before(:each) do
- WebMock.disable_net_connect!
- WebMock.reset!
- end
-
- describe "callbacks" do
- before(:each) do
- @easy = Typhoeus::Easy.new
- @easy.url = "http://example.com"
- end
-
- it "should call on_success with 2xx response" do
- body = "on_success fired"
- stub_request(:any, "example.com").to_return(:body => body)
-
- test = nil
- @easy.on_success do |c|
- test = c.response_body
- end
- @easy.perform
- test.should == body
- end
-
- it "should call on_failure with 5xx response" do
- response_code = 599
- stub_request(:any, "example.com").
- to_return(:status => [response_code, "Server On Fire"])
-
- test = nil
- @easy.on_failure do |c|
- test = c.response_code
- end
- @easy.perform
- test.should == response_code
- end
-
-
- it "should call callbacks only success callback on success request" do
- stub_request(:any, "example.com")
- order = []
- @easy.on_success {|*args| order << :on_success }
- @easy.on_failure {|*args| order << :on_failure }
- @easy.perform
-
- order.should == [:on_success]
- end
-
- it "should call callbacks only failed callback on failed request" do
- stub_request(:any, "example.com").to_return(:status => [500, ""])
- order = []
- @easy.on_success {|*args| order << :on_success }
- @easy.on_failure {|*args| order << :on_failure }
- @easy.perform
-
- order.should == [:on_failure]
- end
- end
- end
-
- end
-end
View
47 spec/typhoeus_easy_spec_helper.rb
@@ -1,47 +0,0 @@
-require 'ostruct'
-
-module TyphoeusEasySpecHelper
- class FakeTyphoeusEasyError < StandardError; end
-
- def http_request(method, uri, options = {}, &block)
- uri = Addressable::URI.heuristic_parse(uri)
-
- easy = Typhoeus::Easy.new
- easy.method = method
- easy.url = uri.omit(:userinfo).to_s
- easy.auth = { :username => uri.user, :password => uri.password } if uri.user
- easy.request_body = options[:body] if options[:body]
- easy.headers = options[:headers] if options[:headers]
- easy.timeout = 2000
- easy.connect_timeout = 2000
-
- easy.perform
-
- # status, response_headers = Curl::Easy::WebmockHelper.parse_header_string(curl.header_str)
- raise FakeTyphoeusEasyError.new if easy.response_code.to_s == "0"
- response = Typhoeus::Response.new(:headers => easy.response_header)
- OpenStruct.new(
- :body => easy.response_body,
- :headers => WebMock::Util::Headers.normalize_headers(join_array_values(response.headers_hash)),
- :status => easy.response_code.to_s,
- :message => response.status_message
- )
- end
-
- def client_timeout_exception_class
- Curl::Err::TimeoutError
- end
-
- def connection_refused_exception_class
- FakeTyphoeusEasyError
- end
-
- def setup_expectations_for_real_request(options = {})
- #TODO
- end
-
- def http_library
- :typhoeus
- end
-
-end

0 comments on commit fe52257

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