# -*- coding: utf-8 -*- require 'rubygems' require 'test/unit' require File.join(File.dirname(__FILE__), "..", "lib", "apricoteatsgorilla") class ApricotEatsGorillaTest < Test::Unit::TestCase def test_soap_response_example xml = ' secret example ' expected = {'authValue' => {'token' => 'secret', 'client' => 'example'}} result = ApricotEatsGorilla.soap_response_to_hash(xml) assert_equal expected, result end def test_that_boolean_string_values_are_converted_to_actual_boolean_objects xml = 'truefalsesomething' expected = {'yes' => true, 'no' => false, 'txt' => 'something'} result = ApricotEatsGorilla.soap_response_to_hash(xml, '//root') assert_equal expected, result end def test_that_empty_element_tags_are_converted_to_nil xml = 'Jungle Julia' expected = {'name' => 'Jungle Julia', 'email' => nil, 'phone' => nil} result = ApricotEatsGorilla.soap_response_to_hash(xml, '//contact') assert_equal expected, result end def test_that_attributes_get_removed xml = 'black' expected = {'paint' => 'black'} result = ApricotEatsGorilla.soap_response_to_hash(xml, '//todo') assert_equal expected, result end def test_that_node_groups_with_text_values_get_converted_to_arrays xml = 'firstsecond' expected = {'items' => ['first', 'second']} result = ApricotEatsGorilla.soap_response_to_hash(xml, '//root') assert_equal expected, result end def test_that_node_groups_with_nesting_get_converted_to_arrays_with_hashes xml = 'firstsecond' expected = {'items' => [{'name' => 'first'}, {'name' => 'second'}]} result = ApricotEatsGorilla.soap_response_to_hash(xml, '//root') assert_equal expected, result end end