Sha256: 141ad853bb3ea83d2bed798074c0955ba371e65bc427324530b0fbbcc7f4f3a3

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'helper'

describe Faraday::Response::ParseXml do
  context 'when used' do
    let(:multi_xml) { Faraday::Response::ParseXml.new }

    it 'should handle an empty response' do
      empty = multi_xml.on_complete(:body => '')
      empty.should == Hash.new
    end

    it 'should create a Hash from the body' do
      me = multi_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
      me.class.should == Hash
    end

    it 'should handle hashes' do
      me = multi_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
      me['user']['name'].should == 'Erik Michaels-Ober'
      me['user']['screen_name'].should == 'sferik'
    end
  end

  context 'integration test' do
    let(:stubs) { Faraday::Adapter::Test::Stubs.new }
    let(:connection) do
      Faraday::Connection.new do |builder|
        builder.adapter :test, stubs
        builder.use Faraday::Response::ParseXml
      end
    end

    it 'should create a Hash from the body' do
      stubs.get('/hash') {[200, {'content-type' => 'application/xml; charset=utf-8'}, '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>']}
      me = connection.get('/hash').body
      me.class.should == Hash
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
faraday_middleware-0.6.3 spec/parse_xml_spec.rb
faraday_middleware-0.6.0 spec/parse_xml_spec.rb