1 describe :time_params, :shared => true do
2 it "handles string-like second argument" do
3 Time.send(@method, 2008, "12").should == Time.send(@method, 2008, 12)
4 Time.send(@method, 2008, "dec").should == Time.send(@method, 2008, 12)
5 (obj = mock('12')).should_receive(:to_str).and_return("12")
6 Time.send(@method, 2008, obj).should == Time.send(@method, 2008, 12)
9 ruby_bug "#", "1.8.6.114" do
10 # Exclude MRI 1.8.6 because it segfaults. :)
11 # But the problem is fixed in MRI repository already.
12 it "handles string-like second argument" do
13 (obj = mock('dec')).should_receive(:to_str).and_return('dec')
14 Time.send(@method, 2008, obj).should == Time.send(@method, 2008, 12)
18 it "handles string arguments" do
19 Time.send(@method, "2000", "1", "1" , "20", "15", "1").should == Time.send(@method, 2000, 1, 1, 20, 15, 1)
20 Time.send(@method, "1", "15", "20", "1", "1", "2000", :ignored, :ignored, :ignored, :ignored).should == Time.send(@method, 1, 15, 20, 1, 1, 2000, :ignored, :ignored, :ignored, :ignored)
23 it "handles float arguments" do
24 Time.send(@method, 2000.0, 1.0, 1.0, 20.0, 15.0, 1.0).should == Time.send(@method, 2000, 1, 1, 20, 15, 1)
25 Time.send(@method, 1.0, 15.0, 20.0, 1.0, 1.0, 2000.0, :ignored, :ignored, :ignored, :ignored).should == Time.send(@method, 1, 15, 20, 1, 1, 2000, :ignored, :ignored, :ignored, :ignored)
28 it "should accept various year ranges" do
29 Time.send(@method, 1901, 12, 31, 23, 59, 59, 0).wday.should == 2
30 Time.send(@method, 2037, 12, 31, 23, 59, 59, 0).wday.should == 4
32 platform_is :wordsize => 32 do
33 lambda { Time.send(@method, 1900, 12, 31, 23, 59, 59, 0) }.should raise_error(ArgumentError) # mon
34 lambda { Time.send(@method, 2038, 12, 31, 23, 59, 59, 0) }.should raise_error(ArgumentError) # mon
37 platform_is :wordsize => 64 do
38 Time.send(@method, 1900, 12, 31, 23, 59, 59, 0).wday.should == 1
39 Time.send(@method, 2038, 12, 31, 23, 59, 59, 0).wday.should == 5
43 it "throws ArgumentError for out of range values" do
44 # year-based Time.local(year (, month, day, hour, min, sec, usec))
45 # Year range only fails on 32 bit archs
46 platform_is :wordsize => 32 do
47 lambda { Time.send(@method, 1111, 12, 31, 23, 59, 59, 0) }.should raise_error(ArgumentError) # year
49 lambda { Time.send(@method, 2008, 13, 31, 23, 59, 59, 0) }.should raise_error(ArgumentError) # mon
50 lambda { Time.send(@method, 2008, 12, 32, 23, 59, 59, 0) }.should raise_error(ArgumentError) # day
51 lambda { Time.send(@method, 2008, 12, 31, 25, 59, 59, 0) }.should raise_error(ArgumentError) # hour
52 lambda { Time.send(@method, 2008, 12, 31, 23, 61, 59, 0) }.should raise_error(ArgumentError) # min
53 lambda { Time.send(@method, 2008, 12, 31, 23, 59, 61, 0) }.should raise_error(ArgumentError) # sec
55 # second based Time.local(sec, min, hour, day, month, year, wday, yday, isdst, tz)
56 lambda { Time.send(@method, 61, 59, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # sec
57 lambda { Time.send(@method, 59, 61, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # min
58 lambda { Time.send(@method, 59, 59, 25, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # hour
59 lambda { Time.send(@method, 59, 59, 23, 32, 12, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # day
60 lambda { Time.send(@method, 59, 59, 23, 31, 13, 2008, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # month
61 # Year range only fails on 32 bit archs
62 platform_is :wordsize => 32 do
63 lambda { Time.send(@method, 59, 59, 23, 31, 12, 1111, :ignored, :ignored, :ignored, :ignored) }.should raise_error(ArgumentError) # year
67 it "throws ArgumentError for invalid number of arguments" do
68 # Time.local only takes either 1-8, or 10 arguments
70 Time.send(@method, 59, 1, 2, 3, 4, 2008, 0, 0, 0)
71 }.should raise_error(ArgumentError) # 9 go boom
73 # please stop using should_not raise_error... it is implied
74 Time.send(@method, 2008).wday.should == 2
75 Time.send(@method, 2008, 12).wday.should == 1
76 Time.send(@method, 2008, 12, 31).wday.should == 3
77 Time.send(@method, 2008, 12, 31, 23).wday.should == 3
78 Time.send(@method, 2008, 12, 31, 23, 59).wday.should == 3
79 Time.send(@method, 2008, 12, 31, 23, 59, 59).wday.should == 3
80 Time.send(@method, 2008, 12, 31, 23, 59, 59, 0).wday.should == 3
81 Time.send(@method, 59, 1, 2, 3, 4, 2008, :x, :x, :x, :x).wday.should == 4