transport 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,10 @@ module Transport
35
35
  return unless expected_status_code
36
36
  response_code = @http_response.code.to_i
37
37
  response_body = @http_response.body
38
- raise UnexpectedStatusCodeError.new(response_code, response_body) if expected_status_code.to_i != response_code
38
+ valid_status_code = [ expected_status_code ].flatten.compact.reduce(false) do |valid, status_code|
39
+ valid || status_code == response_code
40
+ end
41
+ raise UnexpectedStatusCodeError.new(response_code, response_body) unless valid_status_code
39
42
  end
40
43
 
41
44
  end
@@ -17,3 +17,15 @@ describe "fetch a search query result from google" do
17
17
  end
18
18
 
19
19
  end
20
+
21
+ describe "fetch a search query result from google accepting multiple status codes" do
22
+
23
+ it "should return something" do
24
+ response = Transport::HTTP.request :get,
25
+ "http://www.google.de/search",
26
+ :parameters => { "q" => "transport" },
27
+ :expected_status_code => [ 200, 204 ]
28
+ response.should_not be_nil
29
+ end
30
+
31
+ end
@@ -43,6 +43,13 @@ describe Transport::HTTP do
43
43
  end.should raise_error(Transport::UnexpectedStatusCodeError)
44
44
  end
45
45
 
46
+ it "should raise UnexpectedStatusCodeError if responded status code is a invalid one" do
47
+ @transport.options.merge! :expected_status_code => [ 201, 204 ]
48
+ lambda do
49
+ @transport.perform
50
+ end.should raise_error(Transport::UnexpectedStatusCodeError)
51
+ end
52
+
46
53
  end
47
54
 
48
55
  describe "response" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-10 00:00:00.000000000Z
12
+ date: 2011-10-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &21806220 !ruby/object:Gem::Requirement
16
+ requirement: &23192160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *21806220
24
+ version_requirements: *23192160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: reek
27
- requirement: &21805520 !ruby/object:Gem::Requirement
27
+ requirement: &23191420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '1.2'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *21805520
35
+ version_requirements: *23191420
36
36
  description: Provide a single command interface to perform http/json requests. A spec
37
37
  helper to perform request against a fake server is also included.
38
38
  email: b.phifty@gmail.com