Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/data_structure_spec.rb	(revision 369)
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::DataStructures
+include OpenEHR::RM::DataTypes::Text
+
+describe DataStructure do
+  before(:each) do
+    name = DvText.new(:value => 'test')
+    @data_structure = DataStructure.new(:archetype_node_id => 'at0001',
+                                        :name => name)
+  end
+
+  it 'should be an instance of DataStructure' do
+    @data_structure.should be_an_instance_of DataStructure
+  end
+
+  it 'should raise NotImplementedError' do
+    lambda {
+      @data_structure.as_hierarchy
+    }.should raise_error NotImplementedError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/event_spec.rb	(revision 369)
@@ -0,0 +1,44 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe Event do
+  before(:each) do
+    time = DvDateTime.new(:value => '2009-11-12T10:19:33')
+    state = stub(ItemStructure, :archetype_node_id => 'at0002')
+    origin = DvDateTime.new(:value => '2009-11-11T10:20:40')
+    parent = stub(History, :origin => origin)
+    @event = Event.new(:archetype_node_id => 'at0001',
+                       :name => DvText.new(:value => 'Event test'),
+                       :time => time,
+                       :data => 'data',
+                       :state => state,
+                       :parent => parent)
+  end
+
+  it 'should be an instance of Event' do
+    @event.should be_an_instance_of Event
+  end
+
+  it 'data should be assigned properly' do
+    @event.data.should == 'data'
+  end
+
+  it 'time should be assigned properly' do
+    @event.time.value.should == '2009-11-12T10:19:33'
+  end
+
+  it 'state should be assigned properly' do
+    @event.state.archetype_node_id.should == 'at0002'
+  end
+
+  it 'parent should be properly assigned' do
+    @event.parent.origin.value.should == '2009-11-11T10:20:40'
+  end
+
+  it 'offset should be diff of parent.origin from time' do
+    @event.offset.value.should == 'P0Y0M0W0DT23H58M53S'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/history_spec.rb	(revision 369)
@@ -0,0 +1,67 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe History do
+  before(:each) do
+    origin = DvDateTime.new(:value => '2009-11-01T00:00:00')
+    period = DvDuration.new(:value => 'P1Y2M3W4D')
+    duration = DvDuration.new(:value => 'P0Y0M0W6D')
+    events = [stub(Event, :archetype_node_id => 'at0002')]
+    summary = stub(ItemStructure, :archetype_node_id => 'at0003')
+    @history = History.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'history test'),
+                           :origin => origin,
+                           :period => period,
+                           :duration => duration,
+                           :events => events,
+                           :summary => summary)
+  end
+
+  it 'should be an instance of History' do
+    @history.should be_an_instance_of History
+  end
+
+  it 'origin should be properly assigned' do
+    @history.origin.value.should == '2009-11-01T00:00:00'
+  end
+
+  it 'should raise ArgumentError with nil origin' do
+    lambda {
+      @history.origin = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'period should be properly assigned' do
+    @history.period.value.should == 'P1Y2M3W4D'
+  end
+
+  it 'duration should be properly assigned' do
+    @history.duration.value.should == 'P0Y0M0W6D'
+  end
+
+  it 'is_periodic? should be true when period is not nil' do
+    @history.is_periodic?.should be_true
+  end
+
+  it 'is_periodic? should be false when period is nil' do
+    @history.period = nil
+    @history.is_periodic?.should be_false
+  end
+
+  it 'events should be properly assigned' do
+    @history.events[0].archetype_node_id.should == 'at0002'
+  end
+
+  it 'empty events should raise ArgumentError' do
+    lambda {
+      @history.events = []
+    }.should raise_error ArgumentError
+  end
+
+  it 'summary should be properly assigned' do
+    @history.summary.archetype_node_id.should == 'at0003'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/history/interval_event_spec.rb	(revision 369)
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::History
+include OpenEHR::RM::DataStructures::ItemStructure
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe IntervalEvent do
+  before(:each) do
+    time = DvDateTime.new(:value => '2009-11-12T10:19:33')
+    state = stub(ItemStructure, :archetype_node_id => 'at0002')
+    origin = DvDateTime.new(:value => '2009-11-11T10:20:40')
+    parent = stub(History, :origin => origin)
+    math_function = stub(DvCodedText, :value => 'mean')
+    width = DvDuration.new(:value => 'P0Y2M1W3DT5H7M3S')
+    @interval_event = IntervalEvent.new(:archetype_node_id => 'at0001',
+                                :name => DvText.new(:value => 'Event test'),
+                                :time => time,
+                                :data => 'data',
+                                :width => width,
+                                :math_function => math_function, 
+                                :sample_count => 1234)
+  end
+
+  it 'should be an instance of IntervalEvent' do
+    @interval_event.should be_an_instance_of IntervalEvent
+  end
+
+  it 'width should be assigned properly' do
+    @interval_event.width.value.should == 'P0Y2M1W3DT5H7M3S'
+  end
+
+  it 'math_function should be assigned properly' do
+    @interval_event.math_function.value.should == 'mean'
+  end
+
+  it 'sample_count should be assigned properly' do
+    @interval_event.sample_count.should be_equal 1234
+  end
+
+  it 'should subtract time for interval start time' do
+    @interval_event.interval_start_time.value.should == '2009-09-09T05:12:30+09:00'
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb	(revision 369)
@@ -36,6 +36,10 @@
   end
 
-  it 'retrieve the item with a name' do
+  it 'should return the item with a name' do
     @item_list.named_item('one').name.value.should == 'one'
+  end
+
+  it 'should return nil when item is not exist' do
+    @item_list.named_item('four').should be_nil
   end
 
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_single_spec.rb	(revision 369)
@@ -6,16 +6,24 @@
 
 describe ItemSingle do
-  before(:all) do
-    name = 
-    @element = Element.new(:name => DvText.new('item'),
-                           :archetype_node_id => 'AT0000',
-                           :value => DvQuantity.new())
-    item_single_name = DvText.new('item single')
+  before(:each) do
+    element = stub(Element, :archetype_node_id => 'at0002')
+    item_single_name = DvText.new(:value => 'item single')
     @item_single = ItemSingle.new(:name => item_single_name,
-                                  :archetype_node_id => 'test',
-                                  :item => @element)
-    
+                                  :archetype_node_id => 'at0001',
+                                  :item => element)
   end
 
+  it 'should be an instance of ItemSingle' do
+    @item_single.should be_an_instance_of ItemSingle
+  end
 
+  it 'should raise ArgumentError with nil item' do
+    lambda {
+      @item_single.item = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should return as_hierarchy' do
+    @item_single.as_hierarchy.archetype_node_id.should == 'at0002'
+  end
 end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb	(revision 369)
@@ -45,4 +45,8 @@
   end
 
+  it 'column_count should be 0 when @rows == nil' do
+    @item_table.rows = nil
+    @item_table.column_count.should be_equal 0
+  end
 
   it 's row_names should be cluster cluster' do
@@ -96,4 +100,8 @@
   end
 
+  it 'should be false it has_column with name ten' do
+    @item_table.has_column_with_name?('ten').should be_false
+  end
+
   it 'second row should be named_row four' do
     @item_table.named_row('four').items[1].name.value = 'five'
@@ -126,5 +134,10 @@
 
   it 'should be two element at named cell by row column' do
-    @item_table.element_at_named_cell('cluster', 'two').name.value == 'two'
+    @item_table.element_at_named_cell('cluster', 'three').name.value == 'three'
+  end
+
+  it 'should return nil when rows are nil' do
+    @item_table.rows = nil
+    @item_table.row_count.should be_equal 0
   end
 
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb	(revision 291)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb	(revision 369)
@@ -7,11 +7,13 @@
 describe ItemTree do
   before(:each) do
-    items = %w{one two}.collect do |name|
+    i = 1
+    items = %w{one two three}.collect do |name|
+      i += 1
       Element.new(:name => DvText.new(:value => name),
-                  :archetype_node_id => 'test')
+                  :archetype_node_id => 'at000' + i.to_s)
     end
     name = DvText.new(:value => 'item tree')
     @item_tree = ItemTree.new(:name => name,
-                              :archetype_node_id => 'test',
+                              :archetype_node_id => 'at0001',
                               :items => items)
   end
@@ -26,4 +28,21 @@
 
   it 'has valid element path' do
+    @item_tree.has_element_path?('at0002').should be_true
+  end
+
+  it 'should return false with wrong node' do
+    @item_tree.has_element_path?('at0005').should be_false
+  end
+
+  it 'path at002 should return two' do
+    @item_tree.element_at_path('at0003').name.value.should == 'two'
+  end
+
+  it 'path at005 should return nil' do
+    @item_tree.element_at_path('at0005').should be_nil
+  end
+
+  it 'should returns ItemTree as Cluster' do
+    @item_tree.as_hierarchy.name.value.should == 'item tree'
   end
 end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/cluster_spec.rb	(revision 369)
@@ -0,0 +1,26 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::ItemStructure::Representation
+include OpenEHR::RM::DataTypes::Text
+
+describe Cluster do
+  before(:each) do
+    item = stub(Item)
+    @cluster = Cluster.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'cluster'),
+                           :items => [item, item])
+  end
+
+  it 'should be an isntance of Cluster' do
+    @cluster.should be_an_instance_of Cluster
+  end
+
+  it 'item size should be 2' do
+    @cluster.items.size.should == 2
+  end
+
+  it 'should raise ArgumentError with empty items' do
+    lambda {
+      @cluster.items = []
+    }.should raise_error ArgumentError
+  end
+end
Index: ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb
===================================================================
--- ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb	(revision 369)
+++ ruby/trunk/spec/lib/open_ehr/rm/data_structures/item_structure/representation/element_spec.rb	(revision 369)
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../../../../../../spec_helper'
+include OpenEHR::RM::DataStructures::ItemStructure::Representation
+include OpenEHR::RM::DataTypes::Text
+
+describe Element do
+  before(:each) do
+    value = DvText.new(:value => 'test')
+    @element = Element.new(:archetype_node_id => 'at0001',
+                           :name => DvText.new(:value => 'element'),
+                           :value => value)
+  end
+
+  it 'should be an instance of Element' do
+    @element.should be_an_instance_of Element
+  end
+
+  it 'value should be assigned as test' do
+    @element.value.value.should == 'test'
+  end
+
+  it 'nullflavor should be assigned'
+end
