Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#762 rspec #832

Merged
merged 52 commits into from
Nov 26, 2018
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b910c06
Adds RSpec minimal config
iMacTia Jan 27, 2018
dbd2588
Faraday::Utils specs
iMacTia Jan 27, 2018
e45b970
Adds specs for Faraday::Response::Middleware and Faraday::Response::R…
iMacTia Jan 27, 2018
fcc2f49
Adds specs for Faraday::Response::Logger
iMacTia Jan 27, 2018
6842a8e
Removes minitests that have been turned into specs
iMacTia Jan 27, 2018
2f550e6
Puts back `strawberry.rb` file as it's used by some test...
iMacTia Jan 29, 2018
2596fbb
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Feb 10, 2018
72ae7ca
Converts request_middleware_test into rspec
iMacTia Feb 10, 2018
2230667
Converts parameters_test into rspec
iMacTia Feb 10, 2018
46b16f5
Converts options_test into rspec
iMacTia Feb 11, 2018
fe9c30e
Disables minimum coverage for MiniTest
iMacTia Feb 11, 2018
97bd2e8
Introduces webmock
iMacTia Feb 11, 2018
cc3fed6
fix
iMacTia Feb 11, 2018
296fc9b
Adds tests for Excon, HTTPClient, NetHTTPPersistent, Patron and Typho…
iMacTia Feb 18, 2018
ce7c730
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Mar 8, 2018
d3ec206
Allows to configure features on a per-adapter base
iMacTia Mar 8, 2018
1610d30
Adds common #post adapter tests
iMacTia Mar 8, 2018
575a4af
Isolate http methods tests into a set of shared examples
iMacTia Mar 8, 2018
5c544e6
Skips some tests under Patron as there's an issue with PATCH body (ht…
iMacTia Mar 13, 2018
fc3542f
fixes
iMacTia Mar 19, 2018
1030d2e
Streaming WIP
iMacTia Mar 26, 2018
79746fd
Finish converting streaming tests.
iMacTia Mar 30, 2018
eb08c1e
Updates webmock to fix patron issue with PATCH requests.
iMacTia May 31, 2018
c4f03b7
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Jul 21, 2018
bac1da1
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Sep 21, 2018
50b8568
Fixes small issue with logger spec
iMacTia Sep 21, 2018
752b64f
Switches travis to use RSpec instead of MiniTest
iMacTia Sep 21, 2018
54b24cd
Converts autorization middleware tests.
iMacTia Sep 21, 2018
f774396
Style fixes to headers.rb
iMacTia Sep 28, 2018
7cfc584
Ignores /spec folder from when calculating coverage %.
iMacTia Sep 28, 2018
e1d7548
Test SSL enabled and disabled in the same test run.
iMacTia Sep 28, 2018
20cff7b
Actaully, let's remove it!
iMacTia Sep 28, 2018
e137e0b
Fix proxy and timeout tests.
iMacTia Oct 3, 2018
374ffed
Converts adapters tests to RSpec.
iMacTia Oct 15, 2018
6f46db6
Converts instrumentation tests to RSpec.
iMacTia Oct 15, 2018
30fb4b7
Converts retry middleware tests to RSpec.
iMacTia Oct 29, 2018
62d3f95
Adds new parameters_tests to nested_spec
iMacTia Oct 29, 2018
89df1a1
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Oct 29, 2018
340122a
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Oct 29, 2018
f0ff87b
Converts composite_read_io tests into RSpec
iMacTia Oct 29, 2018
80fdc7e
Adds RSpec for Faraday::Error::ClientError
iMacTia Oct 29, 2018
d49ad85
Converts RackBuilder tests into specs.
iMacTia Oct 30, 2018
393cb2c
No need to run tests twice anymore. SSL yes/no are now both tested.
iMacTia Oct 30, 2018
27b5d5e
Partially convert connection tests into RSpec.
iMacTia Nov 7, 2018
3bc27a2
More connection tests converted into RSpec.
iMacTia Nov 8, 2018
f016ebb
More connection tests converted into RSpec.
iMacTia Nov 8, 2018
e31d7af
More connection tests converted into RSpec.
iMacTia Nov 8, 2018
8826971
More connection tests converted into RSpec.
iMacTia Nov 8, 2018
e5c7f83
More connection tests converted into RSpec.
iMacTia Nov 8, 2018
8b1c857
Complete connection tests convertion into RSpec.
iMacTia Nov 9, 2018
58a3174
Merge branch '1.0' of https://github.com/lostisland/faraday into feat…
iMacTia Nov 26, 2018
4325812
Converts new Net::HTTP::Persistent pool_size tests to Rspec.
iMacTia Nov 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds RSpec for Faraday::Error::ClientError
  • Loading branch information
iMacTia committed Oct 29, 2018
commit 80fdc7ea179dc4bb8945a8c49c96eecc3c690e55
19 changes: 11 additions & 8 deletions lib/faraday/error.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
45 changes: 45 additions & 0 deletions spec/faraday/error_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
RSpec.describe Faraday::Error do
describe Faraday::Error::ClientError do
describe '.initialize' do
subject { described_class.new(exception, response) }
let(:response) { nil }

context 'with exception only' do
let(:exception) { RuntimeError.new('test') }

it { expect(subject.wrapped_exception).to eq(exception) }
it { expect(subject.response).to be_nil }
it { expect(subject.message).to eq(exception.message) }
it { expect(subject.backtrace).to eq(exception.backtrace) }
it { expect(subject.inspect).to eq('#<Faraday::ClientError wrapped=#<RuntimeError: test>>') }
end

context 'with response hash' do
let(:exception) { { status: 400 } }

it { expect(subject.wrapped_exception).to be_nil }
it { expect(subject.response).to eq(exception) }
it { expect(subject.message).to eq('the server responded with status 400') }
it { expect(subject.inspect).to eq('#<Faraday::ClientError response={:status=>400}>') }
end

context 'with string' do
let(:exception) { 'custom message' }

it { expect(subject.wrapped_exception).to be_nil }
it { expect(subject.response).to be_nil }
it { expect(subject.message).to eq('custom message') }
it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: custom message>>') }
end

context 'with anything else #to_s' do
let(:exception) { %w(error1 error2) }

it { expect(subject.wrapped_exception).to be_nil }
it { expect(subject.response).to be_nil }
it { expect(subject.message).to eq('["error1", "error2"]') }
it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: ["error1", "error2"]>>') }
end
end
end
end