1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
require 'spec_helper'
describe FaradayMiddleware::MultiJson::ParseJson do
let(:response) { {:a => 1, :b => 2} }
let(:json) { ::MultiJson.dump(response) }
def connection(options={})
Faraday.new do |builder|
builder.response :multi_json, options
builder.adapter :test do |stub|
stub.get('/') do
[200, {}, json]
end
end
end
end
it 'should parse the response body' do
connection.get('/').body.should == {'a'=>1, 'b'=>2}
end
it 'should delegate options given by builder' do
connection(:symbolize_keys => true).get('/').body.should == response
end
end
describe FaradayMiddleware::MultiJson::EncodeJson do
let(:request) { {:a => 1, :b => 2} }
let(:json) { ::MultiJson.dump(request) }
def connection
Faraday.new do |builder|
builder.request :multi_json
builder.adapter :test do |stub|
stub.post('/update', json) do
[200, {}, json]
end
end
end
end
it 'should parse the request body' do
resp = connection.post('/update', request)
resp.body.should == json
end
end
|