Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/activesupport/test/core_ext/duration_test.rb

Revision 8563, 1.2 kB (checked in by bitsweat, 8 months ago)

require abstract_unit directly since test is in load path

Line 
1 require 'abstract_unit'
2
3 class DurationTest < Test::Unit::TestCase
4   def test_inspect
5     assert_equal '1 month',                         1.month.inspect
6     assert_equal '1 month and 1 day',               (1.month + 1.day).inspect
7     assert_equal '6 months and -2 days',            (6.months - 2.days).inspect
8     assert_equal '10 seconds',                      10.seconds.inspect
9     assert_equal '10 years, 2 months, and 1 day',   (10.years + 2.months + 1.day).inspect
10     assert_equal '7 days',                          1.week.inspect
11     assert_equal '14 days',                         1.fortnight.inspect
12   end
13
14   def test_minus_with_duration_does_not_break_subtraction_of_date_from_date
15     assert_nothing_raised { Date.today - Date.today }
16   end
17
18   def test_plus_with_time
19     assert_equal 1 + 1.second, 1.second + 1, "Duration + Numeric should == Numeric + Duration"
20   end
21
22   def test_argument_error
23     begin
24       1.second.ago('')
25       flunk("no exception was raised")
26     rescue ArgumentError => e
27       assert_equal 'expected a time or date, got ""', e.message, "ensure ArgumentError is not being raised by dependencies.rb"
28     rescue Exception
29       flunk("ArgumentError should be raised, but we got #{$!.class} instead")
30     end
31   end
32 end
Note: See TracBrowser for help on using the browser.