source: ruby/branches/0.5/spec/lib/open_ehr/assumed_library_types/iso8601_date_spec.rb@ 286

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

iso8601 date time completed

File size: 5.7 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 it 'should parse vaild date form' do
34
35 end
36
37 it 'should parse valid adte form' do
38 ISO8601Date.should be_valid_iso8601_date '2009-09-22'
39 end
40
41 it 'should not parse invalid date form' do
42 ISO8601Date.should_not be_valid_iso8601_date '2009-13-54'
43 end
44
45 describe 'year behavior' do
46 it 'should raise ArgumentError with nil year string' do
47 lambda{ISO8601Date.new('-09-02')}.should raise_error ArgumentError
48 end
49
50 it 'should raise ArgumentError with nil year' do
51 lambda{@iso8601date.year = nil}.should raise_error ArgumentError
52 end
53
54 it 'should not raise ArgumentError more than 0 year' do
55 lambda{@iso8601date.year = 0}.should_not raise_error ArgumentError
56 end
57 end
58
59 describe 'month behavior' do
60 it '1 month should not raise ArgumentError' do
61 lambda{@iso8601date.month = 1}.should_not raise_error ArgumentError
62 end
63
64 it '12 month should not raise ArgumentError' do
65 lambda{@iso8601date.month = 12}.should_not raise_error ArgumentError
66 end
67
68 it '13 month should raise ArgumentError' do
69 lambda{@iso8601date.month = 13}.should raise_error ArgumentError
70 end
71
72 it '0 month should raise ArgumentError' do
73 lambda{@iso8601date.month = 0}.should raise_error ArgumentError
74 end
75 end
76
77 describe 'day behavior' do
78 it '0 day should raise ArgumentError' do
79 lambda{@iso8601date.day = 0}.should raise_error ArgumentError
80 end
81 end
82
83 [1,3,5,7,8,10,12].each do |m|
84 describe '#{m}th month behavior' do
85 before do
86 @iso8601date.month = m
87 end
88
89 it 'should have 31 days' do
90 lambda{
91 @iso8601date.day = 31
92 }.should_not raise_error ArgumentError
93 end
94
95 it 'should not have 32 days' do
96 lambda{
97 @iso8601date.day = 32
98 }.should raise_error ArgumentError
99 end
100 end
101 end
102
103 describe 'February and leap year behavior' do
104 before do
105 @iso8601date.month = 2
106 end
107
108 describe '2009(not leap year) behavior' do
109 before do
110 @iso8601date.year = 2009
111 end
112
113 it '2009 should not be leap year' do
114 @iso8601date.should_not be_leapyear 2009
115 end
116
117 it '2009-02-28 should not raise ArgumentError' do
118 lambda{@iso8601date.day = 28}.should_not raise_error ArgumentError
119 end
120
121 it '2009-02-29 should raise ArgumentError' do
122 lambda{@iso8601date.day = 29}.should raise_error ArgumentError
123 end
124 end
125
126 describe '2008(leap year) behavior' do
127 before do
128 @iso8601date.year = 2008
129 end
130
131 it '2008 should be leap year' do
132 @iso8601date.should be_leapyear 2008
133 end
134
135 it '2008-02-29 should not raise ArgumentError' do
136 lambda{@iso8601date.day = 29}.should_not raise_error ArgumentError
137 end
138
139 it '2008-02-30 should raise ArgumentError' do
140 lambda{@iso8601date.day = 30}.should raise_error ArgumentError
141 end
142 end
143
144 describe '2000(irregular leap year' do
145 before do
146 @iso8601date.year = 2000
147 end
148
149 it 'should not leapyear' do
150 @iso8601date.should be_leapyear 2000
151 end
152
153 it '2000-02-29 should not raise ArgumentError' do
154 lambda{@iso8601date.day = 29}.should_not raise_error ArgumentError
155 end
156
157 it '2000-02-30 should raise ArgumentError' do
158 lambda{@iso8601date.day = 30}.should raise_error ArgumentError
159 end
160 end
161 end
162
163 [4,6,9,11].each do |month|
164 describe "#{month}th month behavior" do
165 before do
166 @iso8601date.month = month
167 end
168
169 it '30 day should not raise ArgumentError' do
170 lambda{
171 @iso8601date.day = 30
172 }.should_not raise_error ArgumentError
173 end
174
175 it '31 day should raise ArgumentError' do
176 lambda{
177 @iso8601date.day = 31
178 }.should raise_error ArgumentError
179 end
180 end
181 end
182
183 describe 'partial date data' do
184 describe 'day unknown' do
185 before do
186 @iso8601date.day = nil
187 end
188
189 it 'day should be unknown' do
190 @iso8601date.should be_day_unknown
191 end
192
193 it 'should be 2009-09 as string' do
194 @iso8601date.as_string.should == '2009-09'
195 end
196
197 it 'should be partial' do
198 @iso8601date.is_partial?.should be_true
199 end
200
201 it 'constructor pass partial date' do
202 lambda {
203 ISO8601Date.new('2009-09')
204 }.should_not raise_error ArgumentError
205 end
206
207 after do
208 @iso8601date.day = 10
209 end
210 end
211
212 describe 'month unknown' do
213 before do
214 @iso8601date.day = nil
215 @iso8601date.month = nil
216 end
217
218 it 'should raise ArgumentError with nil month and not nil day' do
219 lambda {
220 @iso8601date.day = 11
221 }.should raise_error ArgumentError
222 end
223
224 it 's as_string should be 2009' do
225 @iso8601date.as_string.should == '2009'
226 end
227
228 it 'constructor pass only year data' do
229 lambda {
230 ISO8601Date.new('2009')
231 }.should_not raise_error ArgumentError
232 end
233 end
234 end
235
236end
Note: See TracBrowser for help on using the repository browser.