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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
describe :time_params, :shared => true do
it "accepts 1 argument (year)" do
Time.send(@method, 2000).should ==
Time.send(@method, 2000, 1, 1, 0, 0, 0)
end
it "accepts 2 arguments (year, month)" do
Time.send(@method, 2000, 2).should ==
Time.send(@method, 2000, 2, 1, 0, 0, 0)
end
it "accepts 3 arguments (year, month, day)" do
Time.send(@method, 2000, 2, 3).should ==
Time.send(@method, 2000, 2, 3, 0, 0, 0)
end
it "accepts 4 arguments (year, month, day, hour)" do
Time.send(@method, 2000, 2, 3, 4).should ==
Time.send(@method, 2000, 2, 3, 4, 0, 0)
end
it "accepts 5 arguments (year, month, day, hour, minute)" do
Time.send(@method, 2000, 2, 3, 4, 5).should ==
Time.send(@method, 2000, 2, 3, 4, 5, 0)
end
it "raises a TypeError if the year is nil" do
lambda { Time.send(@method, nil) }.should raise_error(TypeError)
end
it "accepts nil month, day, hour, minute, and second" do
Time.send(@method, 2000, nil, nil, nil, nil, nil).should ==
Time.send(@method, 2000)
end
it "handles a String year" do
Time.send(@method, "2000").should ==
Time.send(@method, 2000)
end
it "coerces the year with #to_int" do
m = mock(:int)
m.should_receive(:to_int).and_return(1)
Time.send(@method, m).should == Time.send(@method, 1)
end
it "handles a String month given as a numeral" do
Time.send(@method, 2000, "12").should ==
Time.send(@method, 2000, 12)
end
it "handles a String month given as a short month name" do
Time.send(@method, 2000, "dec").should ==
Time.send(@method, 2000, 12)
end
it "coerces the month with #to_str" do
(obj = mock('12')).should_receive(:to_str).and_return("12")
Time.send(@method, 2008, obj).should ==
Time.send(@method, 2008, 12)
end
it "coerces the month with #to_int" do
m = mock(:int)
m.should_receive(:to_int).and_return(1)
Time.send(@method, 2008, m).should == Time.send(@method, 2008, 1)
end
it "handles a String day" do
Time.send(@method, 2000, 12, "15").should ==
Time.send(@method, 2000, 12, 15)
end
it "coerces the day with #to_int" do
m = mock(:int)
m.should_receive(:to_int).and_return(1)
Time.send(@method, 2008, 1, m).should == Time.send(@method, 2008, 1, 1)
end
it "handles a String hour" do
Time.send(@method, 2000, 12, 1, "5").should ==
Time.send(@method, 2000, 12, 1, 5)
end
it "coerces the hour with #to_int" do
m = mock(:int)
m.should_receive(:to_int).and_return(1)
Time.send(@method, 2008, 1, 1, m).should == Time.send(@method, 2008, 1, 1, 1)
end
it "handles a String minute" do
Time.send(@method, 2000, 12, 1, 1, "8").should ==
Time.send(@method, 2000, 12, 1, 1, 8)
end
it "coerces the minute with #to_int" do
m = mock(:int)
m.should_receive(:to_int).and_return(1)
Time.send(@method, 2008, 1, 1, 0, m).should == Time.send(@method, 2008, 1, 1, 0, 1)
end
ruby_bug "6193", "2.0" do
it "handles a String second" do
Time.send(@method, 2000, 12, 1, 1, 1, "8").should ==
Time.send(@method, 2000, 12, 1, 1, 1, 8)
end
end
it "coerces the second with #to_int" do
m = mock(:int)
m.should_receive(:to_int).and_return(1)
Time.send(@method, 2008, 1, 1, 0, 0, m).should == Time.send(@method, 2008, 1, 1, 0, 0, 1)
end
ruby_bug "6193", "2.0" do
it "interprets all numerals as base 10" do
Time.send(@method, "2000", "08", "08", "08", "08", "08").should ==
Time.send(@method, 2000, 8, 8, 8, 8, 8)
Time.send(@method, "2000", "09", "09", "09", "09", "09").should ==
Time.send(@method, 2000, 9, 9, 9, 9, 9)
end
end
ruby_version_is "".."1.9" do
it "ignores fractional seconds as a Float" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1.75)
t.sec.should == 1
t.usec.should == 0
end
end
ruby_version_is "1.9" do
it "handles fractional seconds as a Float" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1.75)
t.sec.should == 1
t.usec.should == 750000
end
it "handles fractional seconds as a Rational" do
t = Time.send(@method, 2000, 1, 1, 20, 15, Rational(99, 10))
t.sec.should == 9
t.usec.should == 900000
end
end
ruby_version_is ""..."1.9.1" do
it "accepts various year ranges" do
Time.send(@method, 1901, 12, 31, 23, 59, 59, 0).wday.should == 2
Time.send(@method, 2037, 12, 31, 23, 59, 59, 0).wday.should == 4
not_compliant_on :rubinius do
platform_is :wordsize => 32 do
lambda {
Time.send(@method, 1900, 12, 31, 23, 59, 59, 0)
}.should raise_error(ArgumentError) # mon
lambda {
Time.send(@method, 2038, 12, 31, 23, 59, 59, 0)
}.should raise_error(ArgumentError) # mon
end
platform_is :wordsize => 64 do
Time.send(@method, 1900, 12, 31, 23, 59, 59, 0).wday.should == 1
Time.send(@method, 2038, 12, 31, 23, 59, 59, 0).wday.should == 5
end
end
deviates_on :rubinius do
Time.send(@method, 1900, 12, 31, 23, 59, 59, 0).wday.should == 1
Time.send(@method, 2038, 12, 31, 23, 59, 59, 0).wday.should == 5
end
end
not_compliant_on :rubinius do
platform_is :wordsize => 32 do
it "raises an ArgumentError for out of range year" do
lambda {
Time.send(@method, 1111, 12, 31, 23, 59, 59)
}.should raise_error(ArgumentError)
end
end
end
end
ruby_version_is "1.9" do
it "accepts various year ranges" do
Time.send(@method, 1801, 12, 31, 23, 59, 59).wday.should == 4
Time.send(@method, 3000, 12, 31, 23, 59, 59).wday.should == 3
end
end
it "raises an ArgumentError for out of range month" do
lambda {
Time.send(@method, 2008, 13, 31, 23, 59, 59)
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError for out of range day" do
lambda {
Time.send(@method, 2008, 12, 32, 23, 59, 59)
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError for out of range hour" do
lambda {
Time.send(@method, 2008, 12, 31, 25, 59, 59)
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError for out of range minute" do
lambda {
Time.send(@method, 2008, 12, 31, 23, 61, 59)
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError for out of range second" do
lambda {
Time.send(@method, 2008, 12, 31, 23, 59, 61)
}.should raise_error(ArgumentError)
end
it "raises ArgumentError when given 9 arguments" do
lambda { Time.send(@method, *[0]*9) }.should raise_error(ArgumentError)
end
it "raises ArgumentError when given 11 arguments" do
lambda { Time.send(@method, *[0]*11) }.should raise_error(ArgumentError)
end
it "returns subclass instances" do
c = Class.new(Time)
c.send(@method, 2008, "12").should be_kind_of(c)
end
end
describe :time_params_10_arg, :shared => true do
it "handles string arguments" do
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)
end
it "handles float arguments" do
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)
end
ruby_version_is ""..."1.9.1" do
it "raises an ArgumentError for out of range values" do
lambda {
Time.send(@method, 61, 59, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # sec
lambda {
Time.send(@method, 59, 61, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # min
lambda {
Time.send(@method, 59, 59, 25, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # hour
lambda {
Time.send(@method, 59, 59, 23, 32, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # day
lambda {
Time.send(@method, 59, 59, 23, 31, 13, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # month
# Year range only fails on 32 bit archs
not_compliant_on :rubinius do
platform_is :wordsize => 32 do
lambda {
Time.send(@method, 59, 59, 23, 31, 12, 1111, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # year
end
end
end
end
ruby_version_is "1.9" do
it "raises an ArgumentError for out of range values" do
lambda {
Time.send(@method, 61, 59, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # sec
lambda {
Time.send(@method, 59, 61, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # min
lambda {
Time.send(@method, 59, 59, 25, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # hour
lambda {
Time.send(@method, 59, 59, 23, 32, 12, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # day
lambda {
Time.send(@method, 59, 59, 23, 31, 13, 2008, :ignored, :ignored, :ignored, :ignored)
}.should raise_error(ArgumentError) # month
end
end
end
describe :time_params_microseconds, :shared => true do
it "handles microseconds" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1, 123)
t.usec.should == 123
end
ruby_version_is "".."1.9" do
it "ignores fractional microseconds as a Float" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1, 1.75)
t.usec.should == 1
end
end
ruby_version_is "1.9" do
it "handles fractional microseconds as a Float" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1, 1.75)
t.usec.should == 1
t.nsec.should == 1750
end
it "handles fractional microseconds as a Rational" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1, Rational(99, 10))
t.usec.should == 9
t.nsec.should == 9900
end
it "ignores fractional seconds if a passed whole number of microseconds" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1.75, 2)
t.sec.should == 1
t.usec.should == 2
t.nsec.should == 2000
end
it "ignores fractional seconds if a passed fractional number of microseconds" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1.75, Rational(99, 10))
t.sec.should == 1
t.usec.should == 9
t.nsec.should == 9900
end
end
end
|