source: ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso_8601_date_spec.rb@ 259

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

support/identification package moving from test/unit to rspec

File size: 4.8 KB
Line 
1require File.dirname(__FILE__) + '/../../../spec_helper'
2include OpenEHR::AssumedLibraryTypes
3
4describe ISO8601Date do
5 before do
6 @iso8601date = ISO8601Date.new('2009-09-10')
7 end
8
9 it 'should be an instance of ISO8601Date' do
10 @iso8601date.should be_an_instance_of ISO8601Date
11 end
12
13 it 'year should be equal 2009' do
14 @iso8601date.year.should be_equal 2009
15 end
16
17 it 'month should be equal 9' do
18 @iso8601date.month.should be_equal 9
19 end
20
21 it 'day should be equal 10' do
22 @iso8601date.day.should be_equal 10
23 end
24
25 it 'should be 2009-09-10 as_string' do
26 @iso8601date.as_string.should == '2009-09-10'
27 end
28
29 it 'should be extended ' do
30 @iso8601date.is_extended?.should be_true
31 end
32
33 describe 'year behavior' do
34 it 'should raise ArgumentError with nil year string' do
35 lambda{ISO8601Date.new('-09-02')}.should raise_error ArgumentError
36 end
37
38 it 'should raise ArgumentError with nil year' do
39 lambda{@iso8601date.year = nil}.should raise_error ArgumentError
40 end
41
42 it 'should not raise ArgumentError more than 0 year' do
43 lambda{@iso8601date.year = 0}.should_not raise_error ArgumentError
44 end
45 end
46
47 describe 'month behavior' do
48 it '1 month should not raise ArgumentError' do
49 lambda{@iso8601date.month = 1}.should_not raise_error ArgumentError
50 end
51
52 it '12 month should not raise ArgumentError' do
53 lambda{@iso8601date.month = 12}.should_not raise_error ArgumentError
54 end
55
56 it '13 month should raise ArgumentError' do
57 lambda{@iso8601date.month = 13}.should raise_error ArgumentError
58 end
59
60 it '0 month should raise ArgumentError' do
61 lambda{@iso8601date.month = 0}.should raise_error ArgumentError
62 end
63 end
64
65 describe 'day behavior' do
66 it '0 day should raise ArgumentError' do
67 lambda{@iso8601date.day = 0}.should raise_error ArgumentError
68 end
69 end
70
71 [1,3,5,7,8,10,12].each do |m|
72 describe '#{m}th month behavior' do
73 before do
74 @iso8601date.month = m
75 end
76
77 it 'should have 31 days' do
78 lambda{
79 @iso8601date.day = 31
80 }.should_not raise_error ArgumentError
81 end
82
83 it 'should not have 32 days' do
84 lambda{
85 @iso8601date.day = 32
86 }.should raise_error ArgumentError
87 end
88 end
89 end
90
91 describe 'February and leap year behavior' do
92 before do
93 @iso8601date.month = 2
94 end
95
96 describe '2009(not leap year) behavior' do
97 before do
98 @iso8601date.year = 2009
99 end
100
101 it '2009-02-28 should not raise ArgumentError' do
102 lambda{@iso8601date.day = 28}.should_not raise_error ArgumentError
103 end
104
105 it '2009-02-29 should raise ArgumentError' do
106 lambda{@iso8601date.day = 29}.should raise_error ArgumentError
107 end
108 end
109
110 describe '2008(leap year) behavior' do
111 before do
112 @iso8601date.year = 2008
113 end
114
115 it '2008-02-29 should not raise ArgumentError' do
116 lambda{@iso8601date.day = 29}.should_not raise_error ArgumentError
117 end
118
119 it '2008-02-30 should raise ArgumentError' do
120 lambda{@iso8601date.day = 30}.should raise_error ArgumentError
121 end
122 end
123
124 describe '2000(irregular leap year' do
125 before do
126 @iso8601date.year = 2000
127 end
128
129 it '2000-02-29 should not raise ArgumentError' do
130 lambda{@iso8601date.day = 29}.should_not raise_error ArgumentError
131 end
132
133 it '2000-02-30 should raise ArgumentError' do
134 lambda{@iso8601date.day = 30}.should raise_error ArgumentError
135 end
136 end
137 end
138
139 [4,6,9,11].each do |month|
140 describe "#{month}th month behavior" do
141 before do
142 @iso8601date.month = month
143 end
144
145 it '30 day should not raise ArgumentError' do
146 lambda{
147 @iso8601date.day = 30
148 }.should_not raise_error ArgumentError
149 end
150
151 it '31 day should raise ArgumentError' do
152 lambda{
153 @iso8601date.day = 31
154 }.should raise_error ArgumentError
155 end
156 end
157 end
158
159 describe 'partial date data' do
160 describe 'day unknown' do
161 before do
162 @iso8601date.day = nil
163 end
164
165 it 'day should be unknown' do
166 @iso8601date.should be_day_unknown
167 end
168
169 it 'should be 2009-09 as string' do
170 @iso8601date.as_string.should == '2009-09'
171 end
172
173 it 'should be partial' do
174 @iso8601date.is_partial?.should be_true
175 end
176
177 after do
178 @iso8601date.day = 10
179 end
180 end
181
182 describe 'month unknown' do
183 before do
184 @iso8601date.day = nil
185 @iso8601date.month = nil
186 end
187
188 it 'should raise ArgumentError with nil month and not nil day' do
189 lambda {
190 @iso8601date.day = 11
191 }.should raise_error ArgumentError
192 end
193 end
194 end
195
196end
Note: See TracBrowser for help on using the repository browser.