http-exceptions 0.1.0 → 0.1.1

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: 3dd2e0213e9efb0ed35cb07bd193f9b86ce0f9d5
4
- data.tar.gz: 243069506cecfd6c0ddfc1bd547147316a555f18
3
+ metadata.gz: 03bd2eec282320ea2757da660f823694333ec23d
4
+ data.tar.gz: aa793159eb0c1f53c1528a250f7272664e41f871
5
5
  SHA512:
6
- metadata.gz: 7deb67a6d04d8eb57c9e23a57862630f241f1958b5e3fc7378abcd9510ec36fc5f909211a4c07d5ffcef4289877b7ad966c4e7d82d6f6ae6f516737c237ea810
7
- data.tar.gz: e106195b15e6c5edb957d7a26549b19c3f8ccabb2af0ab9388d5bae449d9f20a9c0219be35d5a57eafa3ef5a3e6d30ef22d9c3dc092ada8d0d687ddca2dee872
6
+ metadata.gz: dd355b76607a59d58bb287af11e062e0912ddb08cd0adca784ca96cc373bb0194a9ccfdbe768c66473becd39c1253d4246c1f267f10e4910e597b6b1090fb0dc
7
+ data.tar.gz: bbc6ecf77d7ec8913adafe9e7b19ae008d76f3a42f4cf0ee102670882361c2ed83e81dbe5ebeb3454721303f0217ce72886ae89b8e2908aeeb7af5a0a78ab324
@@ -6,11 +6,11 @@ require 'http/exceptions/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "http-exceptions"
8
8
  spec.version = Http::Exceptions::VERSION
9
- spec.authors = ["Simon Mathieu"]
10
- spec.email = ["simon.math@gmail.com"]
11
- spec.summary = %q{An easy way to rescue exceptions that might be thrown by your Http library}
12
- spec.description = %q{An easy way to rescue exceptions that might be thrown by your Http library}
13
- spec.homepage = ""
9
+ spec.authors = ["Simon Mathieu", "Russell Smith"]
10
+ spec.email = ["simon.math@gmail.com", "russ@rainforestqa.com"]
11
+ spec.summary = %q{An easy way to rescue exceptions that might be thrown by your HTTP library}
12
+ spec.description = %q{An easy way to rescue exceptions that might be thrown by your HTTP library}
13
+ spec.homepage = "https://github.com/rainforestapp/http-exceptions"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -29,7 +29,7 @@ module Http
29
29
  end
30
30
 
31
31
  def self.check_response!(res)
32
- raise HttpException.new(response: res) unless (200...300).include?(res.code)
32
+ raise HttpException.new(response: res) unless (200...300).include?(res.code.to_i)
33
33
  res
34
34
  end
35
35
 
@@ -1,5 +1,5 @@
1
1
  module Http
2
2
  module Exceptions
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Http::Exceptions do
4
- let(:invalid_response) { double(code: 400, body: '') }
5
- let(:valid_response) { double(code: 200) }
4
+ let(:code) { 200 }
5
+ let(:response) { double(code: code, body: '') }
6
6
 
7
7
  class TestException < RuntimeError
8
8
  end
9
9
 
10
10
  describe ".wrap_exception" do
11
- let(:supported_exception_class) { Http::Exceptions::Configuration::DEFAULT_EXCEPTIONS_TO_CONVERT.first }
11
+ let(:supported_exception_class) { Http::Exceptions::Configuration::DEFAULT_EXCEPTIONS_TO_CONVERT.first }
12
12
  let(:unsupported_exception_class) { TestException }
13
13
 
14
14
  context "when exception class is supported" do
@@ -47,30 +47,54 @@ describe Http::Exceptions do
47
47
  end
48
48
 
49
49
  describe ".check_response!" do
50
- it "raises exception on non-200 response" do
51
- expect do
52
- described_class.check_response!(invalid_response)
53
- end.to raise_error(Http::Exceptions::HttpException)
50
+ shared_examples 'invalid response' do |error_status_code|
51
+ context "when the response code is not a 200" do
52
+ let(:code) { error_status_code }
53
+
54
+ it "raises exception" do
55
+ expect do
56
+ described_class.check_response!(response)
57
+ end.to raise_error(Http::Exceptions::HttpException)
58
+ end
59
+ end
60
+
61
+ it "the raised exception contains the response" do
62
+ begin
63
+ described_class.check_response!(response)
64
+ rescue Http::Exceptions::HttpException => e
65
+ expect(e.response).to eq(response)
66
+ end
67
+ end
54
68
  end
55
69
 
56
- it "the raised exception contains the response" do
57
- begin
58
- described_class.check_response!(invalid_response)
59
- rescue Http::Exceptions::HttpException => e
60
- expect(e.response).to eq(invalid_response)
70
+ shared_examples 'valid response' do |successful_status_code|
71
+ context "when the response code is a 200" do
72
+ let(:code) { successful_status_code }
73
+
74
+ it "returns the response" do
75
+ expect(described_class.check_response!(response)).to eq(response)
76
+ end
61
77
  end
62
78
  end
63
79
 
64
- it "returns the response on valid response" do
65
- expect(described_class.check_response!(valid_response)).to eq(valid_response)
80
+ context "when the response code is an integer" do
81
+ it_behaves_like 'invalid response', 400
82
+ it_behaves_like 'valid response', 200
83
+ end
84
+
85
+ context "when the response code is a string" do
86
+ it_behaves_like 'invalid response', '400'
87
+ it_behaves_like 'valid response', '200'
66
88
  end
67
89
  end
68
90
 
69
91
  describe ".wrap_and_check" do
70
- it "raises exception on bad response" do
92
+ let(:code) { 400 }
93
+
94
+ it "raises an exception on a response with an error code" do
71
95
  expect do
72
96
  described_class.wrap_and_check do
73
- invalid_response
97
+ response
74
98
  end
75
99
  end.to raise_error(Http::Exceptions::HttpException)
76
100
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
8
+ - Russell Smith
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
12
+ date: 2016-08-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -38,16 +39,16 @@ dependencies:
38
39
  - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
- description: An easy way to rescue exceptions that might be thrown by your Http library
42
+ description: An easy way to rescue exceptions that might be thrown by your HTTP library
42
43
  email:
43
44
  - simon.math@gmail.com
45
+ - russ@rainforestqa.com
44
46
  executables: []
45
47
  extensions: []
46
48
  extra_rdoc_files: []
47
49
  files:
48
50
  - ".gitignore"
49
51
  - ".rspec"
50
- - ".rvmrc"
51
52
  - ".travis.yml"
52
53
  - Gemfile
53
54
  - LICENSE.txt
@@ -61,7 +62,7 @@ files:
61
62
  - spec/http/exceptions/configuration_spec.rb
62
63
  - spec/http_exception_spec.rb
63
64
  - spec/spec_helper.rb
64
- homepage: ''
65
+ homepage: https://github.com/rainforestapp/http-exceptions
65
66
  licenses:
66
67
  - MIT
67
68
  metadata: {}
@@ -84,9 +85,8 @@ rubyforge_project:
84
85
  rubygems_version: 2.5.1
85
86
  signing_key:
86
87
  specification_version: 4
87
- summary: An easy way to rescue exceptions that might be thrown by your Http library
88
+ summary: An easy way to rescue exceptions that might be thrown by your HTTP library
88
89
  test_files:
89
90
  - spec/http/exceptions/configuration_spec.rb
90
91
  - spec/http_exception_spec.rb
91
92
  - spec/spec_helper.rb
92
- has_rdoc:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 2.2.0@http-exceptions --create