Sha256: 1a61ec23e92eb4ab5d3634913f8e6111133820340561cd593ec581ff6a17b5f9

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

require 'helper'
require 'lolsoap/envelope'
require 'lolsoap/response'

module LolSoap
  describe Response do
    let(:request) { OpenStruct.new(:soap_namespace => Envelope::SOAP_1_2, :soap_version => '1.2', :output => Object.new) }
    let(:doc) { Nokogiri::XML(File.read(TEST_ROOT + '/fixtures/stock_quote_response.xml')) }

    subject { Response.new(request, doc) }

    describe '.parse' do
      it 'raises an error if there is invalid XML' do
        lambda { Response.parse(request, '<a') }.must_raise Nokogiri::XML::SyntaxError
      end
    end

    describe '#body' do
      it 'returns the first node under the envelope body' do
        subject.body.must_equal doc.at_xpath('/soap:Envelope/soap:Body/m:GetStockPriceResponse')
      end
    end

    describe '#body_hash' do
      it 'builds a hash from the body node' do
        builder = OpenStruct.new(:output => Object.new)
        builder_klass = MiniTest::Mock.new
        builder_klass.expect(:new, builder, [subject.body, request.output])

        subject.body_hash(builder_klass).must_equal builder.output
      end
    end

    describe '#header' do
      it 'returns the header element' do
        subject.header.must_equal doc.at_xpath('/soap:Envelope/soap:Header')
      end
    end

    it 'should return the soap fault' do
      response = Response.new(request, Nokogiri::XML(File.read(TEST_ROOT + '/fixtures/stock_quote_fault.xml')))
      response.fault.wont_equal nil
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lolsoap-0.6.1 test/unit/test_response.rb
lolsoap-0.6.0 test/unit/test_response.rb
lolsoap-0.5.1 test/unit/test_response.rb
lolsoap-0.5.0 test/unit/test_response.rb
lolsoap-0.4.2 test/unit/test_response.rb
lolsoap-0.4.1 test/unit/test_response.rb
lolsoap-0.4.0 test/unit/test_response.rb