rest-client 1.3.0 → 1.3.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.

Potentially problematic release.


This version of rest-client might be problematic. Click here for more details.

data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
data/history.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.3.1
2
+
3
+ - added compatibility to enable responses in exception to act like Net::HTTPResponse
4
+
1
5
  # 1.3.0
2
6
 
3
7
  - a block can be used to process a request's result, this enable to handle custom error codes or paththrought (design by Cyril Rohr)
@@ -1,5 +1,17 @@
1
1
  module RestClient
2
2
 
3
+ # Compatibility : make the Response act like a Net::HTTPResponse when needed
4
+ module ResponseForException
5
+ def method_missing symbol, *args
6
+ if net_http_res.respond_to? symbol
7
+ warn "[warning] The response contained in an RestClient::Exception is now a RestClient::Response instead of a Net::HTTPResponse, please update your code"
8
+ net_http_res.send symbol, *args
9
+ else
10
+ super
11
+ end
12
+ end
13
+ end
14
+
3
15
  # This is the base RestClient exception class. Rescue it if you want to
4
16
  # catch any exception that your request might raise
5
17
  # You can get the status code by e.http_code, or see anything about the
@@ -11,6 +23,9 @@ module RestClient
11
23
 
12
24
  def initialize response = nil
13
25
  @response = response
26
+
27
+ # compatibility: this make the exception behave like a Net::HTTPResponse
28
+ response.extend ResponseForException
14
29
  end
15
30
 
16
31
  def http_code
@@ -1,5 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/base'
2
2
 
3
+ require 'webmock/rspec'
4
+ include WebMock
5
+
3
6
  describe RestClient::Exception do
4
7
  it "sets the exception message to ErrorMessage" do
5
8
  RestClient::ResourceNotFound.new.message.should == 'Resource Not Found'
@@ -17,10 +20,11 @@ describe RestClient::RequestFailed do
17
20
  end
18
21
 
19
22
  it "stores the http response on the exception" do
23
+ response = "response"
20
24
  begin
21
- raise RestClient::RequestFailed, :response
25
+ raise RestClient::RequestFailed, response
22
26
  rescue RestClient::RequestFailed => e
23
- e.response.should == :response
27
+ e.response.should == response
24
28
  end
25
29
  end
26
30
 
@@ -40,10 +44,11 @@ end
40
44
 
41
45
  describe RestClient::ResourceNotFound do
42
46
  it "also has the http response attached" do
47
+ response = "response"
43
48
  begin
44
- raise RestClient::ResourceNotFound, :response
49
+ raise RestClient::ResourceNotFound, response
45
50
  rescue RestClient::ResourceNotFound => e
46
- e.response.should == :response
51
+ e.response.should == response
47
52
  end
48
53
  end
49
54
  end
@@ -60,4 +65,15 @@ describe "backwards compatibility" do
60
65
  it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
61
66
  RestClient::Request::RequestFailed.should == RestClient::RequestFailed
62
67
  end
68
+
69
+ it "make the exception's response act like an Net::HTTPResponse" do
70
+ body = "body"
71
+ stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
72
+ begin
73
+ RestClient.get "www.example.com"
74
+ raise
75
+ rescue RestClient::ResourceNotFound => e
76
+ e.response.body.should == body
77
+ end
78
+ end
63
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins