require File.dirname(__FILE__) + '/../../../../../spec_helper' include OpenEhr::RM::DataStructures::ItemStructure include OpenEhr::RM::DataStructures::ItemStructure::Representation include OpenEhr::RM::DataTypes::Text def row(args) return args.collect do |n| Element.new(:name => DvText.new(n), :archetype_node_id => 'test') end end def cluster_builder(name,rows) return Cluster.new(:name => DvText.new(name), :archetype_node_id => 'test', :items => rows) end describe ItemTable do before(:each) do row1 = row(%w{one two three}) row2 = row(%w{four five six}) rows = [row1, row2].collect{|r| cluster_builder('cluster',r)} @item_table = ItemTable.new(:name => DvText.new('item table'), :archetype_node_id => 'test', :rows => rows) end it 'should be an instance of ItemTable' do @item_table.should be_an_instance_of ItemTable end it 's row count should be 2' do @item_table.row_count.should be_equal 2 end it 's row_count should be 0 when rows are nil' do @item_table.rows = nil @item_table.row_count.should be_equal 0 end it 's column_count should be 3' do @item_table.column_count.should be_equal 3 end it 's row_names should be cluster cluster' do @item_table.row_names.should == %w{cluster cluster}.collect{|n| DvText.new(n)} end it 's row_names should be empty when items are nil' do @item_table.rows = nil @item_table.row_names.should == [] end it 's column_names should one two three' do @item_table.column_names.should == %w{one two three}.collect{|s| DvText.new(s)} end it 's column_names should empty when items aer nil' do @item_table.rows = nil @item_table.column_names.should == [] end it 's ith_row(integer) should be ith row' do @item_table.ith_row(2).items[1].name.value.should == 'five' end it 'should be invalid index under 0' do lambda {@item_table.ith_row(0) }.should raise_error(ArgumentError) end end