require File.dirname(__FILE__) + '/../../../spec_helper' require File.dirname(__FILE__) + '/sample_archetype_spec' require 'rexml/document' include OpenEHR::Serializer describe XMLSerializer do it_should_behave_like 'sample archetype' before(:all) do current_dir = File.dirname(__FILE__) xml_file = File.open(current_dir + '/openEHR-EHR-SECTION.test.v1.xml') xml = xml_file.readlines class << xml def unindent(s,e,num) self[s..e].collect{|line| line[num..-1]}.join end end @sample_header = xml.unindent(2, 11, 2) @sample_description = xml.unindent(12, 27, 2) @sample_definition = xml.unindent(28, 37, 2) @sample_ontology = xml.unindent(38, 56, 2) @sample_xml = xml.join xml_file.close end before(:each) do @xml_serializer = XMLSerializer.new(@archetype) end it 'should be an instance of XMLSerializer' do @xml_serializer.should be_an_instance_of XMLSerializer end it 'should return XML formatted header' do @xml_serializer.header.should == @sample_header end it 'should return XML formatted description' do @xml_serializer.description.should == @sample_description end it 'should return XML formatted definition' do @xml_serializer.definition.should == @sample_definition end it 'should return XML formatted ontology' do @xml_serializer.ontology.should == @sample_ontology end it 'should equal sample hash' do hashed_xml = Hash.from_xml @xml_serializer.serialize archetype_hash = hashed_xml['archetype'] hashed_sample = Hash.from_xml @sample_xml sample_hash = hashed_sample['archetype'] archetype_hash.should be_eql sample_hash end end