Skip to content

Commit

Permalink
Extend specs for Date.iso8601
Browse files Browse the repository at this point in the history
Include a few invalid inputs, mostly to illustrate the difference
between `Date.iso8601` and `Date._iso8601`
  • Loading branch information
herwinw committed Nov 13, 2023
1 parent 71cfe8c commit c6e9c28
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions library/date/iso8601_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
d.should == Date.civil(-4712, 1, 1)
end

it "raises a Date::Error if the argument is a invalid Date" do
-> {
Date.iso8601('invalid')
}.should raise_error(Date::Error, "invalid date")
end

it "raises a Date::Error when passed a nil" do
-> {
Date.iso8601(nil)
}.should raise_error(Date::Error, "invalid date")
end

it "raises a TypeError when passed an Object" do
-> { Date.iso8601(Object.new) }.should raise_error(TypeError)
end
Expand All @@ -32,4 +44,13 @@
h = Date._iso8601('invalid')
h.should == {}
end

it "returns an empty hash if the argument is nil" do
h = Date._iso8601(nil)
h.should == {}
end

it "raises a TypeError when passed an Object" do
-> { Date._iso8601(Object.new) }.should raise_error(TypeError)
end
end

0 comments on commit c6e9c28

Please sign in to comment.