Browse files

Adding a year_range method upon request

  • Loading branch information...
1 parent f887339 commit 7607c13e8e5289e5a1937fbf2cc2686f791f34f2 @robbyrussell committed Mar 24, 2008
Showing with 23 additions and 0 deletions.
  1. +8 −0 lib/year_after_year.rb
  2. +15 −0 spec/year_after_year_spec.rb
View
8 lib/year_after_year.rb
@@ -5,5 +5,13 @@ module YearAfterYear
def current_year
Time.now.strftime('%Y')
end
+
+ def year_range(start_year)
+ if start_year.to_s == current_year
+ current_year
+ else
+ start_year.to_s + '-' + current_year
+ end
+ end
end
end
View
15 spec/year_after_year_spec.rb
@@ -10,3 +10,18 @@
current_year.should == '2006'
end
end
+
+describe PlanetArgon::YearAfterYear, 'year_range()' do
+ before(:each) do
+ t = mock('Time')
+ Time.stub!(:now).and_return( Time.parse( 'Sun Jan 27 15:31:39 -0800 2006' ) )
+ end
+
+ it 'should return a range of years when provided a start year' do
+ year_range(2004).should == '2004-2006'
+ end
+
+ it 'should return only the current year if the start year is the same' do
+ year_range(2006).should == '2006'
+ end
+end

0 comments on commit 7607c13

Please sign in to comment.