require File.dirname(__FILE__) + '/../../../spec_helper' include OpenEHR::AssumedLibraryTypes describe ISO8601Date do before do @iso8601date = ISO8601Date.new('2009-09-10') end it 'should be an instance of ISO8601Date' do @iso8601date.should be_an_instance_of ISO8601Date end it 'year should be equal 2009' do @iso8601date.year.should be_equal 2009 end it 'month should be equal 9' do @iso8601date.month.should be_equal 9 end it 'day should be equal 10' do @iso8601date.day.should be_equal 10 end it 'should be 2009-09-10 as_string' do @iso8601date.as_string.should == '2009-09-10' end describe 'year behavior' do it 'should raise ArgumentError with nil year string' do lambda{ISO8601Date.new('-09-02')}.should raise_error ArgumentError end it 'should raise ArgumentError with nil year' do lambda{@iso8601date.year = nil}.should raise_error ArgumentError end it 'should not raise ArgumentError more than 0 year' do lambda{@iso8601date.year = 0}.should_not raise_error ArgumentError end end describe 'month behavior' do it '1 month should not raise ArgumentError' do lambda{@iso8601date.month = 1}.should_not raise_error ArgumentError end it '12 month should not raise ArgumentError' do lambda{@iso8601date.month = 12}.should_not raise_error ArgumentError end it '13 month should raise ArgumentError' do lambda{@iso8601date.month = 13}.should raise_error ArgumentError end it '0 month should raise ArgumentError' do lambda{@iso8601date.month = 0}.should raise_error ArgumentError end end describe 'day behavior' do it '0 day should raise ArgumentError' do lambda{@iso8601date.day = 0}.should raise_error ArgumentError end end describe 'January behavior' do before do @iso8601date.month = 1 end it 'January should have 31 days' do lambda{@iso8601date.day = 31}.should_not raise_error ArgumentError end it 'January should not have 32 days' do lambda{@iso8601date.month = 32}.should raise_error ArgumentError end end describe 'February and leap year behavior' do before do @iso8601date.month = 2 end describe '2009(not leap year) behavior' do before do @iso8601date.year = 2009 end it '2009-02-28 should not raise ArgumentError' do lambda{@iso8601date.day = 28}.should_not raise_error ArgumentError end it '2009-02-29 should raise ArgumentError' do lambda{@iso8601date.day = 29}.should raise_error ArgumentError end end describe '2008(leap year) behavior' do before do @iso8601date.year = 2008 end it '2008-02-29 should not raise ArgumentError' do lambda{@iso8601date.day = 29}.should_not raise_error ArgumentError end it '2008-02-30 should raise ArgumentError' do lambda{@iso8601date.day = 30}.should raise_error ArgumentError end end describe '2000(irregular leap year' do before do @iso8601date.year = 2000 end it '2000-02-29 should not raise ArgumentError' do lambda{@iso8601date.day = 29}.should_not raise_error ArgumentError end it '2000-02-30 should raise ArgumentError' do lambda{@iso8601date.day = 30}.should raise_error ArgumentError end end end describe 'March behavior' do before do @iso8601date.month = 3 end it '31 day should not raise ArgumentError' do lambda{@iso8601date.day = 31}.should_not raise_error ArgumentError end it '32 day should raise ArgumentError' do lambda{@iso8601date.day = 32}.should raise_error ArgumentError end end describe 'April behavior' do before do @iso8601date.month = 4 end it '30 day should not raise ArgumentError' do lambda{@iso8601date.day = 30}.should_not raise_error ArgumentError end it '31 day should raise ArgumentError' do lambda{@iso8601date.day = 31}.should raise_error ArgumentError end end end