Sha256: 004a97a9f27245e51b0858e3419cef429aad3a671726ce24d5402440e75c2e2c

Contents?: true

Size: 965 Bytes

Versions: 1

Compression:

Stored size: 965 Bytes

Contents

require 'spec_helper'

module Vacuum
  describe Builder do
    let(:xml) do
      xml = <<-XML.gsub!(/>\s+</, '><').strip!
      <?xml version=\"1.0\" ?>
      <ItemAttributes>
        <Title>Anti-Oedipus</Title>
        <Author>Gilles Deleuze</Author>
        <Author>Felix Guattari</Author>
        <Creator Role="Translator">Robert Hurley</Creator>
      </ItemAttributes>
      XML
      Nokogiri::XML(xml)
    end

    describe '.from_xml' do
      it 'returns a hash' do
        Builder.from_xml(xml).should be_an_instance_of Hash
      end

      it 'handles only childs' do
        Builder.from_xml(xml)['Title'].should eql 'Anti-Oedipus'
      end

      it 'handles arrays' do
        Builder.from_xml(xml)['Author'].should be_a Array
      end

      it 'handles attributes' do
        node = Builder.from_xml(xml)['Creator']
        node['Role'].should eql 'Translator'
        node['__content__'].should eql 'Robert Hurley'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vacuum-0.0.1 spec/vacuum/builder_spec.rb