diff options
Diffstat (limited to 'spec/ruby/library/date/parse_spec.rb')
| -rw-r--r-- | spec/ruby/library/date/parse_spec.rb | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/spec/ruby/library/date/parse_spec.rb b/spec/ruby/library/date/parse_spec.rb index 092c658809..4d655f516e 100644 --- a/spec/ruby/library/date/parse_spec.rb +++ b/spec/ruby/library/date/parse_spec.rb @@ -1,7 +1,7 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/parse', __FILE__) -require File.expand_path('../shared/parse_us', __FILE__) -require File.expand_path('../shared/parse_eu', __FILE__) +require_relative '../../spec_helper' +require_relative 'shared/parse' +require_relative 'shared/parse_us' +require_relative 'shared/parse_eu' require 'date' describe "Date#parse" do @@ -23,7 +23,7 @@ describe "Date#parse" do # Specs using numbers it "throws an argument error for a single digit" do - lambda{ Date.parse("1") }.should raise_error(ArgumentError) + ->{ Date.parse("1") }.should.raise(ArgumentError) end it "parses DD as month day number" do @@ -64,6 +64,28 @@ describe "Date#parse" do d = Date.parse("19101101") d.should == Date.civil(1910, 11, 1) end + + it "raises a TypeError trying to parse non-String-like object" do + -> { Date.parse(1) }.should.raise(TypeError) + -> { Date.parse([]) }.should.raise(TypeError) + end + + it "coerces using to_str" do + c = Class.new do + attr_accessor :string + def to_str + @string + end + end + o = c.new + o.string = "19101101" + + d = Date.parse(o) + d.should == Date.civil(1910, 11, 1) + + # parse should not modify string value + o.to_str.should == "19101101" + end end describe "Date#parse with '.' separator" do @@ -71,7 +93,7 @@ describe "Date#parse with '.' separator" do @sep = '.' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with '/' separator" do @@ -79,7 +101,7 @@ describe "Date#parse with '/' separator" do @sep = '/' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with ' ' separator" do @@ -87,7 +109,7 @@ describe "Date#parse with ' ' separator" do @sep = ' ' end - it_should_behave_like "date_parse" + it_should_behave_like :date_parse end describe "Date#parse with '/' separator US-style" do @@ -95,7 +117,7 @@ describe "Date#parse with '/' separator US-style" do @sep = '/' end - it_should_behave_like "date_parse_us" + it_should_behave_like :date_parse_us end describe "Date#parse with '-' separator EU-style" do @@ -103,7 +125,7 @@ describe "Date#parse with '-' separator EU-style" do @sep = '-' end - it_should_behave_like "date_parse_eu" + it_should_behave_like :date_parse_eu end describe "Date#parse(.)" do |
