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

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

date and time are seeds of headache

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