tests/apricoteatsgorilla_test.rb in smacks-apricoteatsgorilla-0.2.8 vs tests/apricoteatsgorilla_test.rb in smacks-apricoteatsgorilla-0.3.2
- old
+ new
@@ -1,125 +1,5 @@
-# -*- coding: utf-8 -*-
-require 'test/unit'
-require File.join(File.dirname(__FILE__), "..", "lib", "apricoteatsgorilla")
-
-class ApricotEatsGorillaTest < Test::Unit::TestCase
-
- def setup
- ApricotEatsGorilla.sort_keys = true
- end
-
- # xml_to_hash
- def test_xml_to_hash_with_soap_response_example
- xml = '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
- <soap:Body>
- <ns2:authenticateResponse xmlns:ns2="http://v1_0.ws.example.com/">
- <return>
- <authValue>
- <token>secret</token>
- <client>example</client>
- </authValue>
- </return>
- </ns2:authenticateResponse>
- </soap:Body>
- </soap:Envelope>'
- expected = { 'auth_value' => { 'token' => 'secret', 'client' => 'example' } }
-
- result = ApricotEatsGorilla.xml_to_hash(xml, '//return')
- assert_equal expected, result
- end
-
- def test_xml_to_hash_make_sure_boolean_values_get_converted_to_boolean_objects
- xml = '<root><yes>true</yes><no>false</no><txt>something</txt></root>'
- expected = { 'yes' => true, 'no' => false, 'txt' => 'something' }
-
- result = ApricotEatsGorilla.xml_to_hash(xml)
- assert_equal expected, result
- end
-
- def test_xml_to_hash_make_sure_empty_element_tags_get_converted_to_nil
- xml = '<contact><name>Jungle Julia</name><email /><phone/></contact>'
- expected = { 'name' => 'Jungle Julia', 'email' => nil, 'phone' => nil }
-
- result = ApricotEatsGorilla.xml_to_hash(xml)
- assert_equal expected, result
- end
-
- def test_xml_to_hash_make_sure_node_attributes_get_removed
- xml = '<todo><paint subject="chair" color="#000000">black</paint></todo>'
- expected = { 'paint' => 'black' }
-
- result = ApricotEatsGorilla.xml_to_hash(xml)
- assert_equal expected, result
- end
-
- def test_xml_to_hash_make_sure_node_groups_with_text_values_get_converted_to_arrays
- xml = '<root><items>first</items><items>second</items></root>'
- expected = { 'items' => [ 'first', 'second' ] }
-
- result = ApricotEatsGorilla.xml_to_hash(xml)
- assert_equal expected, result
- end
-
- def test_xml_to_hash_make_sure_node_groups_with_nesting_get_converted_to_arrays_with_hashes
- xml = '<root><items><name>first</name></items><items><name>second</name></items></root>'
- expected = { 'items' => [ { 'name' => 'first' }, { 'name' => 'second' } ] }
-
- result = ApricotEatsGorilla.xml_to_hash(xml)
- assert_equal expected, result
- end
-
- # hash_to_xml
- def test_hash_to_xml_with_simple_hash
- hash = { "dude" => "likes beer" }
- expected = "<dude>likes beer</dude>"
-
- result = ApricotEatsGorilla.hash_to_xml(hash)
- assert_equal expected, result
- end
-
- def test_hash_to_xml_with_nested_hash
- hash = { "dude" => { "likes" => "beer", "hates" => "appletini" } }
- expected = "<dude><hates>appletini</hates><likes>beer</likes></dude>"
-
- result = ApricotEatsGorilla.hash_to_xml(hash)
- assert_equal expected, result
- end
-
- def test_hash_to_xml_with_nested_hash_and_array
- hash = { "dude" => { "likes" => [ "beer", "helicopters" ] } }
- expected = "<dude><likes>beer</likes><likes>helicopters</likes></dude>"
-
- result = ApricotEatsGorilla.hash_to_xml(hash)
- assert_equal expected, result
- end
-
- def test_hash_to_xml_with_nested_hash_and_array_containing_a_hash
- hash = { "dude" => { "likes" => [ { "beer" => "a lot" }, { "helicopters" => "a little more" } ] } }
- expected = "<dude><likes><beer>a lot</beer></likes><likes><helicopters>a little more</helicopters></likes></dude>"
-
- result = ApricotEatsGorilla.hash_to_xml(hash)
- assert_equal expected, result
- end
-
- # soap_envelope
- def test_soap_envelope_without_namespace_and_block_returns_pure_envelope
- expected = '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">' <<
- '<env:Body></env:Body></env:Envelope>'
-
- result = ApricotEatsGorilla.soap_envelope
- assert_equal expected, result
- end
-
- def test_soap_envelope_with_namespace_and_block_returns_envelope_with_namespace_and_content
- expected = '<env:Envelope ' <<
- 'xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" ' <<
- 'xmlns:wsdl="http://example.com">' <<
- '<env:Body><id>123</id></env:Body></env:Envelope>'
-
- result = ApricotEatsGorilla.soap_envelope("wsdl" => "http://example.com") do
- "<id>123</id>"
- end
- assert_equal expected, result
- end
-
-end
+$:.unshift(File.join(File.dirname(__FILE__), "apricoteatsgorilla"))
+require "shortcut_method_test"
+require "xml_to_hash_test"
+require "hash_to_xml_test"
+require "soap_envelope_test"
\ No newline at end of file