http-exceptions 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ffca1fda1f057ce3a70dc47630a23fd567de208
4
- data.tar.gz: 19c46b249e069e3e5c5ce90b39edf979e23a62f9
3
+ metadata.gz: b2b8379b87bb1870f177fcd13945a60429904e58
4
+ data.tar.gz: 3a6315754839e85a1284174c2bf8799225eede32
5
5
  SHA512:
6
- metadata.gz: 2cfbced68908a3db07560fd8fe00104b3fe5e2167b52368d272b4f4d199911fcebf149ce6d8fa8fd1a32aac3897a64411f176d2f90ed23bc412e60aab551f0a9
7
- data.tar.gz: 15a95d10cd078497d30925bddd477ae76bb96a420001815019a4921500ea9e931ccb917089caa66fe59df42c506e83045de8e928dd5e4697b29610569444cd46
6
+ metadata.gz: d485c0b6fe6f40b0c98f40437f8a878faa701251975460bf8b7607f60c3c1f89518dfe8b45a66f4e06a20b9761e6c75a6197ac576a45dad3120763a47499b2de
7
+ data.tar.gz: e091b9790f5ee5e2c99233c829d402749c6248a284099de9f22d6ca225dad0fab72f14901489b2eb8a8d3402c89ea9b836e6c688e1be5edeb40e79798dd33357
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.0.0
5
+ - 1.9.3
6
+ script: bundle exec rspec spec
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in http-exceptions.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/rainforestapp/http-exceptions.png?branch=master)](https://travis-ci.org/rainforestapp/http-exceptions)
2
+
1
3
  # Http::Exceptions
2
4
 
3
5
  Http::Exceptions provides an easy way to rescue exceptions that might be thrown by your Http library.
@@ -30,7 +32,7 @@ response = Http::Exceptions.wrap_exception do
30
32
  end
31
33
  ```
32
34
 
33
- Raise an exception is the return code of the API call is not `2XX`.
35
+ Raise an exception if the return code of the API call is not `2XX`.
34
36
 
35
37
  ```ruby
36
38
  response = Http::Exceptions.wrap_and_check do
@@ -6,8 +6,8 @@ module Http
6
6
  EXCEPTIONS = [
7
7
  SocketError,
8
8
  Errno::ETIMEDOUT,
9
- Net::ReadTimeout,
10
- Net::OpenTimeout,
9
+ (Net.const_defined?(:ReadTimeout) ? Net::ReadTimeout : EOFError),
10
+ (Net.const_defined?(:OpenTimeout) ? Net::ReadTimeout : EOFError),
11
11
  Net::ProtocolError,
12
12
  Errno::ECONNREFUSED,
13
13
  Errno::EHOSTDOWN,
@@ -3,9 +3,9 @@ module Http
3
3
  class HttpException < RuntimeError
4
4
  attr_reader :response, :original_exception
5
5
 
6
- def initialize(original_exception: nil, response: nil)
7
- @response = response
8
- @original_exception = original_exception
6
+ def initialize(options = {})
7
+ @original_exception = options[:original_exception]
8
+ @response = options[:response]
9
9
  msg = "An error as occured while processing response."
10
10
  msg += " Status #{response.code}\n#{response.body}" if response
11
11
  msg += " Original Exception: #{original_exception}" if original_exception
@@ -1,5 +1,5 @@
1
1
  module Http
2
2
  module Exceptions
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Http::Exceptions do
4
+ let(:invalid_response) { double(code: 400, body: '') }
5
+ let(:valid_response) { double(code: 200) }
6
+
7
+ class TestException < RuntimeError
8
+ end
9
+
10
+ describe ".wrap_exception" do
11
+ it "raises an HttpException on supported http exceptions" do
12
+ expect do
13
+ described_class.wrap_exception do
14
+ raise SocketError
15
+ end
16
+ end.to raise_error(Http::Exceptions::HttpException)
17
+ end
18
+
19
+ it "saves the original exception against the HttpException" do
20
+ begin
21
+ described_class.wrap_exception do
22
+ raise SocketError
23
+ end
24
+ rescue Http::Exceptions::HttpException => e
25
+ expect(e.original_exception).to be_a(SocketError)
26
+ end
27
+ end
28
+
29
+ it "ignores other exceptions" do
30
+ expect do
31
+ described_class.wrap_exception do
32
+ raise TestException
33
+ end
34
+ end.to raise_error(TestException)
35
+ end
36
+ end
37
+
38
+ describe ".check_response!" do
39
+ it "raises exception on non-200 response" do
40
+ expect do
41
+ described_class.check_response!(invalid_response)
42
+ end.to raise_error(Http::Exceptions::HttpException)
43
+ end
44
+
45
+ it "the raised exception contains the response" do
46
+ begin
47
+ described_class.check_response!(invalid_response)
48
+ rescue Http::Exceptions::HttpException => e
49
+ expect(e.response).to eq(invalid_response)
50
+ end
51
+ end
52
+
53
+ it "returns the response on valid response" do
54
+ expect(described_class.check_response!(valid_response)).to eq(valid_response)
55
+ end
56
+ end
57
+
58
+ describe ".wrap_and_check" do
59
+ it "raises exception on bad response" do
60
+ expect do
61
+ described_class.wrap_and_check do
62
+ invalid_response
63
+ end
64
+ end.to raise_error(Http::Exceptions::HttpException)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,91 @@
1
+ require 'http/exceptions'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
+ # For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,7 +46,9 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".rspec"
49
50
  - ".rvmrc"
51
+ - ".travis.yml"
50
52
  - Gemfile
51
53
  - LICENSE.txt
52
54
  - README.md
@@ -55,6 +57,8 @@ files:
55
57
  - lib/http/exceptions.rb
56
58
  - lib/http/exceptions/http_exception.rb
57
59
  - lib/http/exceptions/version.rb
60
+ - spec/http_exception_spec.rb
61
+ - spec/spec_helper.rb
58
62
  homepage: ''
59
63
  licenses:
60
64
  - MIT
@@ -79,4 +83,6 @@ rubygems_version: 2.2.2
79
83
  signing_key:
80
84
  specification_version: 4
81
85
  summary: An easy way to rescue exceptions that might be thrown by your Http library
82
- test_files: []
86
+ test_files:
87
+ - spec/http_exception_spec.rb
88
+ - spec/spec_helper.rb