spec/time_spec.rb in darian_calendar-1.0 vs spec/time_spec.rb in darian_calendar-1.1.0
- old
+ new
@@ -17,14 +17,11 @@
it 'aliases day to sol and week day to week sol' do
@mars_time.day.should == @mars_time.sol
@mars_time.week_day.should == @mars_time.week_sol
end
- end
-
- describe 'initialize method' do
- it 'converts earth time to mars time' do
+ it 'verifies all attributes' do
@mars_time.year.should == 214
@mars_time.month.should == 14
@mars_time.sol.should == 26
@mars_time.hour.should == 20
@mars_time.min.should == 10
@@ -35,10 +32,11 @@
@mars_time.sol_of_season.should == 53
@mars_time.month_of_season.should == 1
@mars_time.sol_of_year.should == 387
@mars_time.week_sol.should == 5
end
+
end
describe 'class methods' do
describe '.from_earth' do
@@ -53,12 +51,12 @@
end
end
describe '.today' do
it 'returns current mars date' do
- ::Date.should_receive(:today).and_return(@earth_date)
- DarianCalendar::Time.today.should == DarianCalendar::Date.from_earth(@earth_date)
+ ::Date.stub(:today).and_return(@earth_date)
+ DarianCalendar::Time.today.should == DarianCalendar::Date.by_digits(214, 14, 26)
end
end
describe '.now' do
it 'returns current mars time' do
@@ -71,10 +69,118 @@
it 'parses a json string and creates a mars date' do
DarianCalendar::Time.from_json(@mars_time_json).should == @mars_time
end
end
+ describe '.by_digits' do
+ context 'no digits are given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits}.to raise_error(ArgumentError, 'Invalid year')
+ end
+ end
+ context 'invalid month is given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits(214, -5)}.to raise_error(ArgumentError, 'Invalid month')
+ end
+ end
+ context 'invalid sol is given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits(214, 14, 35)}.to raise_error(ArgumentError, 'Invalid sol')
+ end
+ end
+ context 'invalid sol for a month is given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits(214, 24, 28)}.to raise_error(ArgumentError, 'Invalid sol for this month')
+ end
+ end
+
+ context 'invalid hour is given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits(214, 24, 28, 32)}.to raise_error(ArgumentError, 'Invalid hour')
+ end
+ end
+
+ context 'invalid minute is given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits(214, 24, 28, 20, 72)}.to raise_error(ArgumentError, 'Invalid minute')
+ end
+ end
+
+ context 'invalid second is given' do
+ it 'should raise an argument error' do
+ expect{DarianCalendar::Time.by_digits(214, 24, 28, 20, 10, -18)}.to raise_error(ArgumentError, 'Invalid second')
+ end
+ end
+
+ context 'only year is given' do
+ it 'returns the first of the month 1 of the given year and 00:00:00' do
+ date = DarianCalendar::Time.by_digits(214)
+ date.year.should == 214
+ date.month.should == 1
+ date.sol.should == 1
+ date.hour.should == 0
+ date.min.should == 0
+ date.sec.should == 0
+ end
+ end
+ context 'only year and month are given' do
+ it 'returns the first of the given month and year and 00:00:00' do
+ date = DarianCalendar::Time.by_digits(214, 14)
+ date.year.should == 214
+ date.month.should == 14
+ date.sol.should == 1
+ date.hour.should == 0
+ date.min.should == 0
+ date.sec.should == 0
+ end
+ end
+ context 'all date but no time digits are given' do
+ it 'returns the date for the given digits and 00:00:00' do
+ date = DarianCalendar::Time.by_digits(214, 14, 26)
+ date.year.should == 214
+ date.month.should == 14
+ date.sol.should == 26
+ date.hour.should == 0
+ date.min.should == 0
+ date.sec.should == 0
+ end
+ end
+ context 'all date digits and hour are given' do
+ it 'returns the date for the given digits and 20:00:00' do
+ date = DarianCalendar::Time.by_digits(214, 14, 26, 20)
+ date.year.should == 214
+ date.month.should == 14
+ date.sol.should == 26
+ date.hour.should == 20
+ date.min.should == 0
+ date.sec.should == 0
+ end
+ end
+ context 'all date digits, hour and minute are given' do
+ it 'returns the date for the given digits and 20:10:00' do
+ date = DarianCalendar::Time.by_digits(214, 14, 26, 20, 10)
+ date.year.should == 214
+ date.month.should == 14
+ date.sol.should == 26
+ date.hour.should == 20
+ date.min.should == 10
+ date.sec.should == 0
+ end
+ end
+ context 'all digits are given' do
+ it 'returns the date for the given digits and 20:10:02' do
+ date = DarianCalendar::Time.by_digits(214, 14, 26, 20, 10, 2)
+ date.year.should == 214
+ date.month.should == 14
+ date.sol.should == 26
+ date.hour.should == 20
+ date.min.should == 10
+ date.sec.should == 2
+ end
+ end
+ end
+
end
describe 'instance methods' do
describe '#<=>' do
@@ -172,10 +278,16 @@
it 'returns "5"' do
mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::AQUA)
mars_time.week_sol_name.should == '5'
end
end
+ context 'calendar type is anything else' do
+ it 'returns ""' do
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, :nothing)
+ mars_time.week_sol_name.should == ''
+ end
+ end
end
describe '#month_name' do
context 'calendar type is not set' do
it 'returns "Mithuna"' do
@@ -208,9 +320,15 @@
end
context 'calendar type is "Aqua"' do
it 'returns "14"' do
mars_time = DarianCalendar::Time.from_earth(@earth_time, DarianCalendar::CalendarTypes::AQUA)
mars_time.month_name.should == '14'
+ end
+ end
+ context 'calendar type is anything else' do
+ it 'returns ""' do
+ mars_time = DarianCalendar::Time.from_earth(@earth_time, :nothing)
+ mars_time.month_name.should == ''
end
end
end
end