public
Description: My assistance repo w/ minor tweaks (original @ http://assistance.rubyforge.org/svn/trunk)
Homepage: http://assistance.rubyforge.org
Clone URL: git://github.com/bricooke/assistance.git
assistance / spec / time_calculations_spec.rb
100644 45 lines (37 sloc) 1.078 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require File.join(File.dirname(__FILE__), 'spec_helper')
 
context "Time calculations" do
  specify "should support conversion of minutes to seconds" do
    1.minute.should == 60
    3.minutes.should == 180
  end
  
  specify "should support conversion of hours to seconds" do
    1.hour.should == 3600
    3.hours.should == 3600 * 3
  end
 
  specify "should support conversion of days to seconds" do
    1.day.should == 86400
    3.days.should == 86400 * 3
  end
 
  specify "should support conversion of weeks to seconds" do
    1.week.should == 86400 * 7
    3.weeks.should == 86400 * 7 * 3
  end
  
  specify "should provide #ago functionality" do
    t1 = Time.now
    t2 = 1.day.ago
    t1.should > t2
    ((t1 - t2).to_i - 86400).abs.should < 2
    
    t1 = Time.now
    t2 = 1.day.before(t1)
    t2.should == t1 - 1.day
  end
 
  specify "should provide #from_now functionality" do
    t1 = Time.now
    t2 = 1.day.from_now
    t1.should < t2
    ((t2 - t1).to_i - 86400).abs.should < 2
    
    t1 = Time.now
    t2 = 1.day.since(t1)
    t2.should == t1 + 1.day
  end
end