trumpet-trumpet 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -2,34 +2,34 @@
2
2
 
3
3
  module Trumpet
4
4
 
5
- # Exception raised when the connection to the server fails
6
- class ServerConnectionError < StandardError; end
7
-
8
5
  # A generic exception to use until we have more specific exceptions
9
6
  # for everything
10
7
  class TrumpetError < StandardError; end
11
8
 
9
+ # Exception raised when the connection to the server fails
10
+ class ServerConnectionError < TrumpetError; end
11
+
12
12
  # HTTP 400 Error
13
- class BadRequest < StandardError; end
13
+ class BadRequest < TrumpetError; end
14
14
 
15
15
  # HTTP 401 Error
16
- class Unauthorized < StandardError; end
16
+ class Unauthorized < TrumpetError; end
17
17
 
18
18
  # HTTP 403 Error
19
- class Forbidden < StandardError; end
19
+ class Forbidden < TrumpetError; end
20
20
 
21
21
  # HTTP 404 Error
22
- class NotFound < StandardError; end
22
+ class NotFound < TrumpetError; end
23
23
 
24
24
  # HTTP 405 Error
25
- class MethodNotAllowed < StandardError; end
25
+ class MethodNotAllowed < TrumpetError; end
26
26
 
27
27
  # HTTP 409 Error
28
- class Conflict < StandardError; end
28
+ class Conflict < TrumpetError; end
29
29
 
30
30
  # HTTP 500 Error
31
- class InternalServerError < StandardError; end
31
+ class InternalServerError < TrumpetError; end
32
32
 
33
33
  # HTTP 501 Error
34
- class NotImplemented < StandardError; end
34
+ class NotImplemented < TrumpetError; end
35
35
  end
@@ -55,6 +55,8 @@ module Trumpet
55
55
  raise Trumpet::NotFound, error_string
56
56
  when 405
57
57
  raise Trumpet::MethodNotAllowed, error_string
58
+ when 409
59
+ raise Trumpet::Conflict, error_string
58
60
  when 500
59
61
  raise Trumpet::InternalServerError, error_string
60
62
  when 501
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Request" do
4
+
5
+ before(:all) do
6
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/badrequest", :status => ["400", "Bad Request"], :string => ['Bad Request'].to_json
7
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/unauthorized", :status => ["401", "Unauthorized"], :string => ['Unauthorized'].to_json
8
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/forbidden", :status => ["403", "Forbidden"], :string => ['Forbidden'].to_json
9
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/notfound", :status => ["404", "Not Found"], :string => ['Not Found'].to_json
10
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/methodnotallowed", :status => ["405", "Method Not Allowed"], :string => ['Method Not Allowed'].to_json
11
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/conflict", :status => ["409", "Conflict"], :string => ['Conflict'].to_json
12
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/internalservererror", :status => ["500", "Internal Server Error"], :string => ['Internal Server Error'].to_json
13
+ FakeWeb.register_uri :get, "#{UNAUTHENTICATED_URI}/notimplemented", :status => ["501", "Not Implemented"], :string => ['Not Implemented'].to_json
14
+ end
15
+
16
+ context "when handling errors" do
17
+ it "should throw a BadRequest exception when it receives a 400 code" do
18
+ lambda { Trumpet::Request.get('/badrequest', :parse_response => false) }.should raise_error(Trumpet::BadRequest)
19
+ end
20
+
21
+ it "should throw an Unauthorized exception when it receives a 401 code" do
22
+ lambda { Trumpet::Request.get('/unauthorized', :parse_response => false) }.should raise_error(Trumpet::Unauthorized)
23
+ end
24
+
25
+ it "should throw a Forbidden exception when it receives a 403 code" do
26
+ lambda { Trumpet::Request.get('/forbidden', :parse_response => false) }.should raise_error(Trumpet::Forbidden)
27
+ end
28
+
29
+ it "should throw a NotFound exception when it receives a 404 code" do
30
+ lambda { Trumpet::Request.get('/notfound', :parse_response => false) }.should raise_error(Trumpet::NotFound)
31
+ end
32
+
33
+ it "should throw a MethodNotAllowed exception when it receives a 405 code" do
34
+ lambda { Trumpet::Request.get('/methodnotallowed', :parse_response => false) }.should raise_error(Trumpet::MethodNotAllowed)
35
+ end
36
+
37
+ it "should throw a Conflict exception when it receives a 409 code" do
38
+ lambda { Trumpet::Request.get('/conflict', :parse_response => false) }.should raise_error(Trumpet::Conflict)
39
+ end
40
+
41
+ it "should throw an InternalServerError exception when it receives a 500 code" do
42
+ lambda { Trumpet::Request.get('/internalservererror', :parse_response => false) }.should raise_error(Trumpet::InternalServerError)
43
+ end
44
+
45
+ it "should throw a NotImplimented exception when it receives a 501 code" do
46
+ lambda { Trumpet::Request.get('/notimplemented', :parse_response => false) }.should raise_error(Trumpet::NotImplemented)
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trumpet-trumpet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Taras
@@ -85,7 +85,7 @@ files:
85
85
  - spec/listener_spec.rb
86
86
  - spec/message_spec.rb
87
87
  - spec/receiver_spec.rb
88
- - spec/resource_spec.rb
88
+ - spec/request_spec.rb
89
89
  - spec/spec_helper.rb
90
90
  - spec/transmitter_spec.rb
91
91
  - spec/user_spec.rb
@@ -120,7 +120,7 @@ test_files:
120
120
  - spec/listener_spec.rb
121
121
  - spec/message_spec.rb
122
122
  - spec/receiver_spec.rb
123
- - spec/resource_spec.rb
123
+ - spec/request_spec.rb
124
124
  - spec/spec_helper.rb
125
125
  - spec/transmitter_spec.rb
126
126
  - spec/user_spec.rb
@@ -1,7 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe "Resource" do
4
- # TODO: write some general specs for behavior that is common to all resources, namely :
5
- # - error handling (exception throwing)
6
- # - instantiating
7
- end