require File.join(File.dirname(__FILE__), "..", "helper") class TestXMLNode < Test::Unit::TestCase context "strip_namespace!" do should "strip the namespace from the XMLNode" do node = XMLNode.new("wsdl:apricot") node.strip_namespace! assert_equal "apricot", node.to_s end end context "to_snake_case!" do should "convert the XMLNode from CamelCase to snake_case" do node = XMLNode.new("ApricotEatsGorilla") node.to_snake_case! assert_equal "apricot_eats_gorilla", node.to_s end should "convert the XMLNode from lowerCamelCase to snake_case" do node = XMLNode.new("apricotEatsGorilla") node.to_snake_case! assert_equal "apricot_eats_gorilla", node.to_s end end context "namespace_from_hash!" do context "with a Hash containing the name of the XMLNode" do should "set the namespace of the XMLNode" do node = XMLNode.new("apricot") node.namespace_from_hash!(:wsdl => [ :apricot ]) assert_equal "apricot", node.to_s assert_equal "", node.to_tag end end context "with a Hash that does not contain the name of the XMLNode" do should "not set the namespace of the XMLNode" do node = XMLNode.new("apricot") node.namespace_from_hash!(:wsdl => [ :some_key ]) assert_equal "", node.to_tag end end end context "to_tag" do context "with a simple XMLNode" do should "return an empty element tag" do node = XMLNode.new("apricot") assert_equal "", node.to_tag end end context "with an XMLNode containing a namespace" do should "return a namespaced empty element tag" do node = XMLNode.new("apricot") node.namespace_from_hash!(:wsdl => [ :apricot ]) assert_equal "", node.to_tag end end context "with an XMLNode containing an attribute" do should "return an empty element tag with an xmlns attribute" do node = XMLNode.new("apricot") node.attributes = { :wsdl => "http://example.com" } assert_equal '', node.to_tag end end context "with an XMLNode containing a body" do should "return an element with a body" do node = XMLNode.new("apricot") node.body = "eats Gorilla" assert_equal 'eats Gorilla', node.to_tag end end end end