Skip to content

Commit

Permalink
Updated the raise_http_4xx to use Array() instead of .to_a so that it…
Browse files Browse the repository at this point in the history
… works under 1.8 and 1.9
  • Loading branch information
NateBarnes committed May 25, 2011
1 parent 708afeb commit 7a1704f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/faraday/response/raise_http_4xx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def error_body(body)
elsif body['error']
": #{body['error']}"
elsif body['errors']
first = body['errors'].to_a.first
first = Array(body['errors']).first
if first.kind_of? Hash
": #{first['message'].chomp}"
else
Expand Down
36 changes: 27 additions & 9 deletions spec/faraday/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,36 @@
502 => Twitter::BadGateway,
503 => Twitter::ServiceUnavailable,
}.each do |status, exception|
context "when HTTP status is #{status}" do
if (status >= 500)
context "when HTTP status is #{status}" do
before do
stub_get('statuses/user_timeline.json').
with(:query => {:screen_name => 'sferik'}).
to_return(:status => status)
end

before do
stub_get('statuses/user_timeline.json').
with(:query => {:screen_name => 'sferik'}).
to_return(:status => status)
it "should raise #{exception.name} error" do
lambda do
@client.user_timeline('sferik')
end.should raise_error(exception)
end
end
else
[nil, "error", "errors"].each do |body|
context "when HTTP status is #{status} and body is #{body}" do
before do
body_message = '{"'+body+'":"test"}' unless body.nil?
stub_get('statuses/user_timeline.json').
with(:query => {:screen_name => 'sferik'}).
to_return(:status => status, :body => body_message)
end

it "should raise #{exception.name} error" do
lambda do
@client.user_timeline('sferik')
end.should raise_error(exception)
it "should raise #{exception.name} error" do
lambda do
@client.user_timeline('sferik')
end.should raise_error(exception)
end
end
end
end
end
Expand Down

0 comments on commit 7a1704f

Please sign in to comment.