Sha256: ca5497a8ad48e586086a489ba4a7ea7d491c314968000ca656f3cfad7c71d7ae
Contents?: true
Size: 1.25 KB
Versions: 4
Compression:
Stored size: 1.25 KB
Contents
require 'helper' class MashifyTest < Test::Unit::TestCase context 'when used' do setup do @stubs = Faraday::Adapter::Test::Stubs.new @conn = Faraday::Connection.new do |builder| builder.adapter :test, @stubs builder.use Faraday::Response::Parse builder.use Faraday::Response::Mashify end end should 'create a Hashie::Mash from the body' do @stubs.get('/hash') {[200, {'content-type' => 'application/json; charset=utf-8'}, '{"name":"Wynn Netherland","username":"pengwynn"}']} me = @conn.get("/hash").body assert_equal 'Wynn Netherland', me.name assert_equal 'pengwynn', me.username end should 'handle arrays' do @stubs.get('/array') {[200, {'content-type' => 'application/json; charset=utf-8'}, '[{"username":"pengwynn"},{"username":"jnunemaker"}]']} us = @conn.get("/array").body assert_equal 'pengwynn', us.first.username assert_equal 'jnunemaker', us.last.username end should 'handle arrays of non-hashes' do @stubs.get('/array/simple') {[200, {'content-type' => 'application/json; charset=utf-8'}, "[123, 456]"]} values = @conn.get("/array/simple").body assert_equal 123, values.first assert_equal 456, values.last end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
faraday_middleware-0.2.3 | test/mashify_test.rb |
faraday_middleware-0.2.2 | test/mashify_test.rb |
faraday_middleware-0.2.1 | test/mashify_test.rb |
faraday_middleware-0.2.0 | test/mashify_test.rb |