Sha256: 8947ef753f29c153caf5420219915b2bdad98e269d53ed0d4e2049b54ece6b2c

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require_relative './../spec_helper'
require_relative './../../examples/library_with_fines'

describe LibraryWithFines do

  let(:xml) { File.read(xml_for('library_with_fines')) }
  let(:library) { LibraryWithFines.from_xml(xml) }

  it "should read nested elements" do
    expect(library.fines).to be_a(Hash)
    library.fines.size == 3
    expect(library.fines).to have_key('talking')
    expect(library.fines['talking']).to match(/Stop asking/)
  end

  class String
    def remove_whitespace
      self.gsub(/\s{2,}/, '').gsub("\n", '')
    end
  end

  it "should write deeply nested elements" do
    xml_out = library.to_xml.to_s
    expect(xml_out.remove_whitespace).to eq(xml.remove_whitespace)
  end

  it "should write two children of library: name and policy" do
    expect(library.to_xml.children.map{|e| e.name }).to eq(['name', 'policy'])
  end

  it "should be re-parsable via .from_xml" do
    lib_reparsed = LibraryWithFines.from_xml(library.to_xml.to_s)
    expect(lib_reparsed.name).to eq(library.name)
    expect(lib_reparsed.fines).to eq(library.fines)
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roxml-4.2.0 spec/examples/library_with_fines_spec.rb
roxml-4.1.1 spec/examples/library_with_fines_spec.rb
roxml-4.1.0 spec/examples/library_with_fines_spec.rb
roxml-4.0.0 spec/examples/library_with_fines_spec.rb