require File.join(File.dirname(__FILE__), "..", "spec_helper")
describe XMLNode do
# strip_namespace!
describe "strip_namespace!" do
it "strips the namespace from the node" do
node = XMLNode.new("wsdl:apricot")
node.strip_namespace!
node.should == "apricot"
end
end
# to_snake_case!
describe "to_snake_case!" do
it "converts the node from CamelCase to snake_case" do
node = XMLNode.new("ApricotEatsGorilla")
node.to_snake_case!
node.should == "apricot_eats_gorilla"
end
it "converts the node from lowerCamelCase to snake_case" do
node = XMLNode.new("apricotEatsGorilla")
node.to_snake_case!
node.should == "apricot_eats_gorilla"
end
end
# namespace_from_hash!
describe "namespace_from_hash!" do
it "namespaces the node if it's included in the given Hash" do
node = XMLNode.new("apricot")
node.namespace_from_hash!(:wsdl => [ :apricot ])
node.should == "apricot"
node.to_tag.should == ""
end
it "does nothing if the node is not included in the given Hash" do
node = XMLNode.new("apricot")
node.namespace_from_hash!(:wsdl => [ :some_key ])
node.should == "apricot"
node.to_tag.should == ""
end
end
# to_tag
describe "to_tag" do
it "returns an empty-element tag for a bare node" do
node = XMLNode.new("apricot")
node.to_tag.should == ""
end
it "returns a namespaced empty-element tag for a namespaced node" do
node = XMLNode.new("apricot")
node.namespace_from_hash!(:wsdl => [ :apricot ])
node.to_tag.should == ""
end
it "returns an empty-element tag with an attribute for an attributed node" do
node = XMLNode.new("apricot")
node.attributes = { :wsdl => "http://example.com" }
node.to_tag.should == ''
end
it "returns a node with body content for a node with content" do
node = XMLNode.new("apricot")
node.body = "eats gorilla"
node.to_tag.should == "eats gorilla"
end
end
end