| | 296 | |
|---|
| | 297 | |
|---|
| | 298 | def test_upto_by_days |
|---|
| | 299 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 300 | end_date = time + 10.days |
|---|
| | 301 | counter = 0 |
|---|
| | 302 | time.upto(end_date) do |date| |
|---|
| | 303 | assert_equal date, (time + counter.days) |
|---|
| | 304 | counter += 1 |
|---|
| | 305 | end |
|---|
| | 306 | |
|---|
| | 307 | end |
|---|
| | 308 | |
|---|
| | 309 | def test_upto_by_months |
|---|
| | 310 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 311 | end_date = time + 10.months |
|---|
| | 312 | counter = 0 |
|---|
| | 313 | time.upto(end_date, :month) do |date| |
|---|
| | 314 | assert_equal date, (time + counter.months) |
|---|
| | 315 | counter += 1 |
|---|
| | 316 | end |
|---|
| | 317 | |
|---|
| | 318 | end |
|---|
| | 319 | |
|---|
| | 320 | def test_upto_by_years |
|---|
| | 321 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 322 | end_date = time + 10.years |
|---|
| | 323 | counter = 0 |
|---|
| | 324 | time.upto(end_date, :year) do |date| |
|---|
| | 325 | assert_equal date, (time + counter.years) |
|---|
| | 326 | counter += 1 |
|---|
| | 327 | end |
|---|
| | 328 | |
|---|
| | 329 | end |
|---|
| | 330 | |
|---|
| | 331 | def test_upto_by_seconds |
|---|
| | 332 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 333 | end_date = time + 10.seconds |
|---|
| | 334 | counter = 0 |
|---|
| | 335 | time.upto(end_date, :seconds) do |date| |
|---|
| | 336 | assert_equal date, (time + counter.seconds) |
|---|
| | 337 | counter += 1 |
|---|
| | 338 | end |
|---|
| | 339 | |
|---|
| | 340 | end |
|---|
| | 341 | |
|---|
| | 342 | def test_upto_by_hours |
|---|
| | 343 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 344 | end_date = time + 10.hours |
|---|
| | 345 | counter = 0 |
|---|
| | 346 | time.upto(end_date, :hours) do |date| |
|---|
| | 347 | assert_equal date, (time + counter.hours) |
|---|
| | 348 | counter += 1 |
|---|
| | 349 | end |
|---|
| | 350 | |
|---|
| | 351 | end |
|---|
| | 352 | |
|---|
| | 353 | def test_upto_by_minutes |
|---|
| | 354 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 355 | end_date = time + 10.minutes |
|---|
| | 356 | counter = 0 |
|---|
| | 357 | time.upto(end_date, :minutes) do |date| |
|---|
| | 358 | assert_equal date, (time + counter.minutes) |
|---|
| | 359 | counter += 1 |
|---|
| | 360 | end |
|---|
| | 361 | |
|---|
| | 362 | end |
|---|
| | 363 | |
|---|
| | 364 | def test_upto_with_bad_step_size |
|---|
| | 365 | time = Time.local(2005, 2, 21, 17, 44, 30) |
|---|
| | 366 | end_date = time + 10.minutes |
|---|
| | 367 | assert_raise NoMethodError do |
|---|
| | 368 | time.upto(end_date, :non_step_size) do |date| |
|---|
| | 369 | puts date |
|---|