1 | require File.dirname(__FILE__) + '/../../../spec_helper'
|
---|
2 | require File.dirname(__FILE__) + '/sample_archetype_spec'
|
---|
3 | require 'rexml/document'
|
---|
4 | include OpenEHR::Serializer
|
---|
5 |
|
---|
6 | describe XMLSerializer do
|
---|
7 | it_should_behave_like 'sample archetype'
|
---|
8 |
|
---|
9 | before(:all) do
|
---|
10 | current_dir = File.dirname(__FILE__)
|
---|
11 | xml_file = File.open(current_dir + '/openEHR-EHR-SECTION.test.v1.xml')
|
---|
12 | xml = xml_file.readlines
|
---|
13 | class << xml
|
---|
14 | def unindent(s,e,num)
|
---|
15 | self[s..e].collect{|line| line[num..-1]}.join
|
---|
16 | end
|
---|
17 | end
|
---|
18 | @sample_header = xml.unindent(2, 11, 2)
|
---|
19 | @sample_description = xml.unindent(12, 27, 2)
|
---|
20 | @sample_definition = xml.unindent(28, 37, 2)
|
---|
21 | @sample_ontology = xml.unindent(38, 56, 2)
|
---|
22 | @sample_xml = xml.join
|
---|
23 | xml_file.close
|
---|
24 | end
|
---|
25 |
|
---|
26 | before(:each) do
|
---|
27 | @xml_serializer = XMLSerializer.new(@archetype)
|
---|
28 | end
|
---|
29 |
|
---|
30 | it 'should be an instance of XMLSerializer' do
|
---|
31 | @xml_serializer.should be_an_instance_of XMLSerializer
|
---|
32 | end
|
---|
33 |
|
---|
34 | it 'should return XML formatted header' do
|
---|
35 | @xml_serializer.header.should == @sample_header
|
---|
36 | end
|
---|
37 |
|
---|
38 | it 'should return XML formatted description' do
|
---|
39 | @xml_serializer.description.should == @sample_description
|
---|
40 | end
|
---|
41 |
|
---|
42 | it 'should return XML formatted definition' do
|
---|
43 | @xml_serializer.definition.should == @sample_definition
|
---|
44 | end
|
---|
45 |
|
---|
46 | it 'should return XML formatted ontology' do
|
---|
47 | @xml_serializer.ontology.should == @sample_ontology
|
---|
48 | end
|
---|
49 |
|
---|
50 | it 'should equal sample hash' do
|
---|
51 | hashed_xml = Hash.from_xml @xml_serializer.serialize
|
---|
52 | archetype_hash = hashed_xml['archetype']
|
---|
53 | hashed_sample = Hash.from_xml @sample_xml
|
---|
54 | sample_hash = hashed_sample['archetype']
|
---|
55 | archetype_hash.should be_eql sample_hash
|
---|
56 | end
|
---|
57 | end
|
---|