Sha256: dd6c252807b34d437ad74dacebeb360e4e0b8c5d9568acd0f5a07b8b4b69305c

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

require 'spec/spec_helper'

describe ROXML::XMLTextRef do
  before do
    @xml = ROXML::XML::Parser.parse %(
<myxml>
  <node>
    <name>first</name>
    <name>second</name>
    <name>third</name>
  </node>
</myxml>)
  end

  context "plain vanilla" do
    before do
      @ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => false), RoxmlObject.new)
    end

    it "should return one instance" do
      @ref.value_in(@xml).should == "first"
    end
    it "should output one instance"
  end
  
  context "with :as => []" do
    before do
      @ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true), RoxmlObject.new)
    end

    it "should collect all instances" do
      @ref.value_in(@xml).should == ["first", "second", "third"]
    end

    it "should output all instances" do
      xml = ROXML::XML::Node.create('myxml')
      @ref.update_xml(xml, ["first", "second", "third"])
      xml.to_s.squeeze(' ').should == @xml.root.to_s.squeeze(' ')
    end
  end
  
  context "when the namespaces are different" do
    before do
      @xml = ROXML::XML::Parser.parse %(
      <myxml xmlns="http://example.com/three" xmlns:one="http://example.com/one" xmlns:two="http://example.com/two">
        <node>
          <one:name>first</one:name>
          <two:name>second</two:name>
          <name>third</name>
        </node>
      </myxml>)
    end

    context "with :namespace => '*'" do
      before do
        @ref = ROXML::XMLTextRef.new(OpenStruct.new(:name => 'name', :wrapper => 'node', :array? => true, :namespace => '*'), RoxmlObject.new)
      end

      it "should collect all instances" do
        @ref.value_in(@xml).should == ["first", "second", "third"]
      end

      it "should output all instances with namespaces" do
        pending "Full namespace write support"
        xml = ROXML::XML::Node.create('myxml')
        @ref.update_xml(xml, ["first", "second", "third"])
        xml.should == @xml.root
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
roxml-3.1.5 spec/xml/text_spec.rb
roxml-3.1.4 spec/xml/text_spec.rb
roxml-3.1.3 spec/xml/text_spec.rb