require 'spec/spec_helper.rb' describe ROXML, "with namespaces" do context "when an included namespace is not defined in the xml" do context "where the missing namespace is the default" do it "should raise" context "but the namespace is declared in the body" do it "should succeed" end end context "where the missing namespace is included in a namespacey from" do it "should raise" context "but the namespace is declared in the body" do it "should succeed" end end context "where the missing namespace is included in an explicit :namespace" do it "should raise" context "but the namespace is declared in the body" do it "should succeed" end end end describe "roxml namespacey declaration", :shared => true do context "with a namespacey :from" do context "and an explicit :namespace" do it "should raise" do proc do Class.new do include ROXML xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespacey_from', :namespace => 'explicit' end end.should raise_error(ROXML::ContradictoryNamespaces) end end context "and :namespace => false" do it "should raise" do proc do Class.new do include ROXML xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespacey_from', :namespace => false end end.should raise_error(ROXML::ContradictoryNamespaces) end end end end describe "roxml namespacey declaration with default", :shared => true do it_should_behave_like "roxml namespacey declaration" it "should use the default namespace" do @instance.default_namespace.should == 'default namespace node' end context "and :namespace => false" do it "should find the namespace-less node" do @instance.default_namespace_with_namespace_false.should == 'namespaceless node' end end context "with an explicit :namespace" do it "should use the explicit namespace" do @instance.default_and_explicit_namespace == 'explicit namespace node' end end context "with a namespace-less :from" do it "should use the default namespace" do @instance.default_namespace_with_namespaceless_from.should == 'default namespace node' end context "and :namespace => false" do it "should find the namespace-less node" do @instance.default_namespace_with_namespaceless_from_and_namespace_false.should == 'namespaceless node' end end context "and an explicit :namespace" do it "should use the explicit namespace" do @instance.default_namespace_with_namespaceless_from_and_explicit_namespace.should == 'explicit namespace node' end end end context "with a namespacey :from" do it "should use the :from namespace" do @instance.default_namespace_with_namespacey_from.should == 'namespacey node' end end end context "with a default namespace declared" do class DefaultNamespaceyObject include ROXML xml_namespace :default_declared xml_reader :default_namespace xml_reader :default_namespace_with_namespace_false, :namespace => false xml_reader :default_and_explicit_namespace, :namespace => 'explicit' xml_reader :default_namespace_with_namespaceless_from, :from => 'with_namespaceless_from' xml_reader :default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit' xml_reader :default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false xml_reader :default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from' # These are handled in the "roxml namespacey declaration" shared spec # xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespaceless_from', :namespace => false # xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespaceless_from', :namespace => 'explicit' end before do @instance = DefaultNamespaceyObject.from_xml(%{ default namespace node namespacey node explicit namespace node namespaceless node default namespace node explicit namespace node namespaceless node }) end it_should_behave_like "roxml namespacey declaration with default" end context "with a default namespace on the root node" do class XmlDefaultNamespaceyObject include ROXML xml_reader :default_namespace xml_reader :default_namespace_with_namespace_false, :namespace => false xml_reader :default_and_explicit_namespace, :namespace => 'explicit' xml_reader :default_namespace_with_namespaceless_from, :from => 'with_namespaceless_from' xml_reader :default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit' xml_reader :default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false xml_reader :default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from' # These are handled in the "roxml namespacey declaration" shared spec # xml_reader :default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespaceless_from', :namespace => false # xml_reader :default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespaceless_from', :namespace => 'explicit' end before do @instance = XmlDefaultNamespaceyObject.from_xml(%{ default namespace node namespacey node explicit namespace node namespaceless node default namespace node explicit namespace node namespaceless node }) end it_should_behave_like "roxml namespacey declaration with default" end context "without a default namespace" do class NamespaceyObject include ROXML xml_reader :no_default_namespace xml_reader :no_default_namespace_with_namespace_false, :namespace => false xml_reader :no_default_but_an_explicit_namespace, :namespace => 'explicit' xml_reader :no_default_namespace_with_namespaceless_from, :from => 'with_namespaceless_from' xml_reader :no_default_namespace_with_namespaceless_from_and_explicit_namespace, :from => 'with_namespaceless_from', :namespace => 'explicit' xml_reader :no_default_namespace_with_namespaceless_from_and_namespace_false, :from => 'with_namespaceless_from', :namespace => false xml_reader :no_default_namespace_with_namespacey_from, :from => 'namespacey:with_namespacey_from' # These are handled in the "roxml namespacey declaration" shared spec # xml_reader :no_default_namespace_with_namespacey_from_and_explicit_namespace, :from => 'namespacey:with_namespacey_from', :namespace => 'explicit' # xml_reader :no_default_namespace_with_namespacey_from_and_namespace_false, :from => 'namespacey:with_namespacey_from', :namespace => false end before do @instance = NamespaceyObject.from_xml(%{ namespacey node explicit namespace node namespaceless node explicit namespace node namespaceless node namespaceless node }) end it_should_behave_like "roxml namespacey declaration" it "should find the namespace-less node" do @instance.no_default_namespace.should == 'namespaceless node' end context "with :namespace => false" do it "should find the namespace-less node" do @instance.no_default_namespace_with_namespace_false.should == 'namespaceless node' end end context "with an explicit :namespace" do it "should use the explicit namespace" do @instance.no_default_but_an_explicit_namespace.should == 'explicit namespace node' end end context "with a namespace-less :from" do it "should find the namespace-less node" do @instance.no_default_namespace_with_namespaceless_from.should == 'namespaceless node' end context "and an explicit :namespace" do it "should use the explicit namespace" do @instance.no_default_namespace_with_namespaceless_from_and_explicit_namespace.should == 'explicit namespace node' end end context "with :namespace => false" do it "should find the namespace-less node" do @instance.no_default_namespace_with_namespaceless_from_and_namespace_false.should == 'namespaceless node' end end end context "with a namespacey :from" do it "should use the :from namespace" do @instance.no_default_namespace_with_namespacey_from.should == 'namespacey node' end end end end