Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test for non JSON response using multi_json

  • Loading branch information...
commit 515f6791c020c8a1b16859c5dd96b491effc9c6f 1 parent e5d86b7
@hone authored
Showing with 32 additions and 12 deletions.
  1. +32 −12 test/multi_json_test.rb
View
44 test/multi_json_test.rb
@@ -4,21 +4,41 @@ class Multi_Json_Test < Test::Unit::TestCase
context 'when used' do
setup do
@stubs = Faraday::Adapter::Test::Stubs.new
- @stubs.get('/me') { [200, {}, "{\"name\":\"Wynn Netherland\",\"username\":\"pengwynn\"}"] }
- end
-
- should 'should parse the body as JSON' do
- conn = Faraday::Connection.new do |builder|
+ @conn = Faraday::Connection.new do |builder|
builder.adapter :test, @stubs
builder.use Faraday::Response::MultiJson
end
-
- me = conn.get("/me").body
- assert me.is_a?(Hash)
- me['name'].should == 'Wynn Netherland'
- me['username'].should == 'pengwynn'
-
+ end
+
+ context "when there is a JSON body" do
+ setup do
+ @stubs.get('/me') { [200, {}, "{\"name\":\"Wynn Netherland\",\"username\":\"pengwynn\"}"] }
+ end
+
+ should 'should parse the body as JSON' do
+ me = @conn.get("/me").body
+ assert me.is_a?(Hash)
+ me['name'].should == 'Wynn Netherland'
+ me['username'].should == 'pengwynn'
+
+ end
+ end
+
+ context "when the JSON body is empty" do
+ setup do
+ @stubs.get('/me') { [200, {}, ""] }
+ end
+
+ should 'still have the status code' do
+ response = @conn.get("/me")
+ response.status.should == 200
+ end
+
+ should 'set body to nil' do
+ response = @conn.get("/me")
+ response.body.should be_nil
+ end
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.