Skip to content

Commit

Permalink
Feature/#762 rspec (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Nov 26, 2018
1 parent 5547802 commit f1b2657
Show file tree
Hide file tree
Showing 75 changed files with 3,516 additions and 3,531 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -7,9 +7,9 @@ pkg/*
tmp
.rvmrc
.ruby-version
.yardoc

## BUNDLER
bin
*.gem
.bundle
Gemfile.lock
Expand Down
3 changes: 3 additions & 0 deletions .rspec
@@ -0,0 +1,3 @@
--require spec_helper
--format documentation
--color
7 changes: 0 additions & 7 deletions .travis.yml
@@ -1,17 +1,11 @@
sudo: false
language: ruby
script: bundle exec script/test
cache: bundler

rvm:
- 2.3
- 2.4
- 2.5
- ruby-head
env:
matrix:
- SSL=no
- SSL=yes
deploy:
provider: rubygems
api_key:
Expand All @@ -21,5 +15,4 @@ deploy:
tags: true
repo: lostisland/faraday
rvm: 2.5
condition: '"$SSL" = "yes"'

6 changes: 6 additions & 0 deletions Gemfile
Expand Up @@ -6,6 +6,10 @@ gem 'ffi-ncurses', '~> 0.3', :platforms => :jruby
gem 'jruby-openssl', '~> 0.8.8', :platforms => :jruby
gem 'rake'

group :development, :test do
gem 'pry'
end

group :test do
gem 'coveralls', :require => false
gem 'em-http-request', '>= 1.1', :require => 'em-http'
Expand All @@ -22,6 +26,8 @@ group :test do
gem 'simplecov'
gem 'sinatra', '~> 1.3'
gem 'typhoeus', '~> 1.3', :require => 'typhoeus'
gem 'rspec', '~> 3.7'
gem 'webmock', '~> 3.4'
end

gemspec
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -4,5 +4,5 @@ task :default => :test

desc "Run all tests"
task :test do
exec 'script/test'
exec 'rspec'
end
14 changes: 14 additions & 0 deletions bin/console
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'faraday'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
9 changes: 9 additions & 0 deletions lib/faraday.rb
Expand Up @@ -17,6 +17,8 @@
#
module Faraday
VERSION = "0.15.3"
METHODS_WITH_QUERY = %w[get head delete]
METHODS_WITH_BODY = %w[post put patch]

class << self
# The root path that Faraday is being loaded from.
Expand Down Expand Up @@ -198,6 +200,13 @@ def register_middleware(autoload_path = nil, mapping = nil)
end
end

# Unregister a previously registered middleware class.
#
# @param key [Symbol] key for the registered middleware.
def unregister_middleware(key)
@registered_middleware.delete(key)
end

# Lookup middleware class with a registered Symbol shortcut.
#
# @param key [Symbol] key for the registered middleware.
Expand Down
3 changes: 2 additions & 1 deletion lib/faraday/adapter/patron.rb
Expand Up @@ -81,7 +81,8 @@ def configure_ssl(session, ssl)

private

CURL_TIMEOUT_MESSAGES = [ "Connection time-out",
CURL_TIMEOUT_MESSAGES = [
"Connection time-out",
"Connection timed out",
"Timed out before name resolve",
"server connect has timed out",
Expand Down
6 changes: 3 additions & 3 deletions lib/faraday/connection.rb
Expand Up @@ -160,7 +160,7 @@ def headers=(hash)
# @return [Faraday::Response]

# @!visibility private
%w[get head delete].each do |method|
METHODS_WITH_QUERY.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(url = nil, params = nil, headers = nil)
run_request(:#{method}, url, nil, headers) { |request|
Expand All @@ -170,7 +170,7 @@ def #{method}(url = nil, params = nil, headers = nil)
end
RUBY
end

# @!method post(url = nil, body = nil, headers = nil)
# Makes a POST HTTP request with a body.
# @!scope class
Expand Down Expand Up @@ -217,7 +217,7 @@ def #{method}(url = nil, params = nil, headers = nil)
# @return [Faraday::Response]

# @!visibility private
%w[post put patch].each do |method|
METHODS_WITH_BODY.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(url = nil, body = nil, headers = nil, &block)
run_request(:#{method}, url, body, headers, &block)
Expand Down
19 changes: 11 additions & 8 deletions lib/faraday/error.rb
@@ -1,6 +1,7 @@
module Faraday
# Faraday error base class.
class Error < StandardError; end
class Error < StandardError;
end

# Faraday client error class.
class ClientError < Error
Expand Down Expand Up @@ -45,15 +46,18 @@ def inspect
end

# A unified client error for failed connections.
class ConnectionFailed < ClientError; end
class ConnectionFailed < ClientError;
end

# A 404 error used in the RaiseError middleware
#
# @see Faraday::Response::RaiseError
class ResourceNotFound < ClientError; end

class ResourceNotFound < ClientError;
end

# Raised by FaradayMiddleware::ResponseMiddleware
class ParsingError < ClientError; end
class ParsingError < ClientError;
end

# A unified client error for timeouts.
class TimeoutError < ClientError
Expand All @@ -69,12 +73,11 @@ class SSLError < ClientError
# Exception used to control the Retry middleware.
#
# @see Faraday::Request::Retry
class RetriableResponse < ClientError; end
class RetriableResponse < ClientError;
end

[:ClientError, :ConnectionFailed, :ResourceNotFound,
:ParsingError, :TimeoutError, :SSLError, :RetriableResponse].each do |const|
Error.const_set(const, Faraday.const_get(const))
end


end
8 changes: 4 additions & 4 deletions lib/faraday/rack_builder.rb
Expand Up @@ -52,8 +52,8 @@ def build(app)
end
end

def initialize(handlers = [])
@adapter = nil
def initialize(handlers = [], adapter = nil)
@adapter = adapter
@handlers = handlers
if block_given?
build(&Proc.new)
Expand Down Expand Up @@ -176,11 +176,11 @@ def to_app(inner_app)
end

def ==(other)
other.is_a?(self.class) && @handlers == other.handlers
other.is_a?(self.class) && @handlers == other.handlers && @adapter == other.adapter
end

def dup
self.class.new(@handlers.dup)
self.class.new(@handlers.dup, @adapter.dup)
end

# ENV Keys
Expand Down

0 comments on commit f1b2657

Please sign in to comment.