File: new_spec.rb

package info (click to toggle)
ruby2.7 2.7.4-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,576 kB
  • sloc: ruby: 849,454; ansic: 697,834; yacc: 45,100; xml: 25,367; pascal: 10,051; javascript: 6,575; sh: 3,848; makefile: 759; cpp: 713; asm: 333; python: 295; lisp: 97; sed: 94; perl: 62; awk: 36
file content (52 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (7)
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
require_relative '../../spec_helper'
require 'date'

describe "DateTime.new" do
  it "sets all values to default if passed no arguments" do
    d = DateTime.new
    d.year.should == -4712
    d.month.should == 1
    d.day.should == 1
    d.hour.should == 0
    d.min.should == 0
    d.sec.should == 0
    d.sec_fraction.should == 0
    d.offset.should == 0
  end

  it "takes the first argument as year" do
    DateTime.new(2011).year.should == 2011
  end

  it "takes the second argument as month" do
    DateTime.new(2011, 2).month.should == 2
  end

  it "takes the third argument as day" do
    DateTime.new(2011, 2, 3).day.should == 3
  end

  it "takes the forth argument as hour" do
    DateTime.new(2011, 2, 3, 4).hour.should == 4
  end

  it "takes the fifth argument as minute" do
    DateTime.new(1, 2, 3, 4, 5).min.should == 5
  end

  it "takes the sixth argument as second" do
    DateTime.new(1, 2, 3, 4, 5, 6).sec.should == 6
  end

  it "takes the seventh argument as an offset" do
    DateTime.new(1, 2, 3, 4, 5, 6, 0.7).offset.should == 0.7
  end

  it "takes the eighth argument as the date of calendar reform" do
    DateTime.new(1, 2, 3, 4, 5, 6, 0.7, Date::ITALY).start().should == Date::ITALY
  end

  it "raises an error on invalid arguments" do
    -> { new_datetime(minute: 999) }.should raise_error(ArgumentError)
  end
end