source: ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb@ 207

Last change on this file since 207 was 207, checked in by KOBAYASHI, Shinji, 15 years ago

refs #54

File size: 2.0 KB
Line 
1require File.dirname(__FILE__) + '/../../../../../spec_helper'
2
3include OpenEhr::RM::DataStructures::ItemStructure
4include OpenEhr::RM::DataStructures::ItemStructure::Representation
5include OpenEhr::RM::DataTypes::Text
6
7def row(args)
8 return args.collect do |n|
9 Element.new(:name => DvText.new(n),
10 :archetype_node_id => 'test')
11 end
12end
13
14def cluster_builder(name,rows)
15 return Cluster.new(:name => DvText.new(name),
16 :archetype_node_id => 'test',
17 :items => rows)
18end
19
20describe ItemTable do
21 before(:each) do
22 row1 = row(%w{one two three})
23 row2 = row(%w{four five six})
24 rows = [row1, row2].collect{|r| cluster_builder('cluster',r)}
25 @item_table = ItemTable.new(:name => DvText.new('item table'),
26 :archetype_node_id => 'test',
27 :rows => rows)
28 end
29
30 it 'should be an instance of ItemTable' do
31 @item_table.should be_an_instance_of ItemTable
32 end
33
34 it 's row count should be 2' do
35 @item_table.row_count.should be_equal 2
36 end
37
38 it 's row_count should be 0 when rows are nil' do
39 @item_table.rows = nil
40 @item_table.row_count.should be_equal 0
41 end
42
43 it 's column_count should be 3' do
44 @item_table.column_count.should be_equal 3
45 end
46
47
48 it 's row_names should be cluster cluster' do
49 @item_table.row_names.should == %w{cluster cluster}.collect{|n| DvText.new(n)}
50 end
51
52 it 's row_names should be empty when items are nil' do
53 @item_table.rows = nil
54 @item_table.row_names.should == []
55 end
56
57 it 's column_names should one two three' do
58 @item_table.column_names.should == %w{one two three}.collect{|s| DvText.new(s)}
59 end
60
61 it 's column_names should empty when items aer nil' do
62 @item_table.rows = nil
63 @item_table.column_names.should == []
64 end
65
66 it 's ith_row(integer) should be ith row' do
67 @item_table.ith_row(2).items[1].name.value.should == 'five'
68 end
69
70 it 'should be invalid index under 0' do
71 lambda {@item_table.ith_row(0) }.should raise_error(ArgumentError)
72 end
73end
Note: See TracBrowser for help on using the repository browser.