summaryrefslogtreecommitdiff
path: root/spec/ruby/library/datetime
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/datetime')
-rw-r--r--spec/ruby/library/datetime/deconstruct_keys_spec.rb10
-rw-r--r--spec/ruby/library/datetime/hour_spec.rb13
-rw-r--r--spec/ruby/library/datetime/iso8601_spec.rb4
-rw-r--r--spec/ruby/library/datetime/min_spec.rb8
-rw-r--r--spec/ruby/library/datetime/minute_spec.rb40
-rw-r--r--spec/ruby/library/datetime/new_spec.rb2
-rw-r--r--spec/ruby/library/datetime/now_spec.rb2
-rw-r--r--spec/ruby/library/datetime/parse_spec.rb12
-rw-r--r--spec/ruby/library/datetime/rfc2822_spec.rb2
-rw-r--r--spec/ruby/library/datetime/sec_spec.rb8
-rw-r--r--spec/ruby/library/datetime/second_fraction_spec.rb4
-rw-r--r--spec/ruby/library/datetime/second_spec.rb43
-rw-r--r--spec/ruby/library/datetime/shared/min.rb40
-rw-r--r--spec/ruby/library/datetime/shared/sec.rb45
-rw-r--r--spec/ruby/library/datetime/to_date_spec.rb2
-rw-r--r--spec/ruby/library/datetime/to_s_spec.rb2
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb2
17 files changed, 117 insertions, 122 deletions
diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb
index 154c024a23..07a7bda881 100644
--- a/spec/ruby/library/datetime/deconstruct_keys_spec.rb
+++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb
@@ -18,16 +18,16 @@ describe "DateTime#deconstruct_keys" do
it "requires one argument" do
-> {
DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "it raises error when argument is neither nil nor array" do
d = DateTime.new(2022, 10, 5, 13, 30)
- -> { d.deconstruct_keys(1) }.should raise_error(TypeError, "wrong argument type Integer (expected Array or nil)")
- -> { d.deconstruct_keys("asd") }.should raise_error(TypeError, "wrong argument type String (expected Array or nil)")
- -> { d.deconstruct_keys(:x) }.should raise_error(TypeError, "wrong argument type Symbol (expected Array or nil)")
- -> { d.deconstruct_keys({}) }.should raise_error(TypeError, "wrong argument type Hash (expected Array or nil)")
+ -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)")
end
it "returns {} when passed []" do
diff --git a/spec/ruby/library/datetime/hour_spec.rb b/spec/ruby/library/datetime/hour_spec.rb
index 8efd5f92f0..5d8e75edcb 100644
--- a/spec/ruby/library/datetime/hour_spec.rb
+++ b/spec/ruby/library/datetime/hour_spec.rb
@@ -15,28 +15,27 @@ describe "DateTime#hour" do
end
it "raises an error for Rational" do
- -> { new_datetime(hour: 1 + Rational(1,2)) }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: 1 + Rational(1,2)) }.should.raise(ArgumentError)
end
it "raises an error for Float" do
- -> { new_datetime(hour: 1.5).hour }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: 1.5).hour }.should.raise(ArgumentError)
end
it "raises an error for Rational" do
- -> { new_datetime(day: 1 + Rational(1,2)) }.should raise_error(ArgumentError)
+ -> { new_datetime(day: 1 + Rational(1,2)) }.should.raise(ArgumentError)
end
it "raises an error, when the hour is smaller than -24" do
- -> { new_datetime(hour: -25) }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: -25) }.should.raise(ArgumentError)
end
it "raises an error, when the hour is larger than 24" do
- -> { new_datetime(hour: 25) }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: 25) }.should.raise(ArgumentError)
end
it "raises an error for hour fractions smaller than -24" do
- -> { new_datetime(hour: -24 - Rational(1,2)) }.should(
- raise_error(ArgumentError))
+ -> { new_datetime(hour: -24 - Rational(1,2)) }.should.raise(ArgumentError)
end
it "adds 1 to day, when 24 hours given" do
diff --git a/spec/ruby/library/datetime/iso8601_spec.rb b/spec/ruby/library/datetime/iso8601_spec.rb
index 457881277a..4368300fd5 100644
--- a/spec/ruby/library/datetime/iso8601_spec.rb
+++ b/spec/ruby/library/datetime/iso8601_spec.rb
@@ -6,5 +6,7 @@ describe "DateTime.iso8601" do
end
describe "DateTime#iso8601" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of DateTime#isoxmlschema8601" do
+ DateTime.instance_method(:iso8601).should == DateTime.instance_method(:xmlschema)
+ end
end
diff --git a/spec/ruby/library/datetime/min_spec.rb b/spec/ruby/library/datetime/min_spec.rb
index a1eaa214cb..ca995a7eed 100644
--- a/spec/ruby/library/datetime/min_spec.rb
+++ b/spec/ruby/library/datetime/min_spec.rb
@@ -1,6 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'shared/min'
+require 'date'
-describe "DateTime.min" do
- it_behaves_like :datetime_min, :min
+describe "DateTime#min" do
+ it "is an alias of DateTime#minute" do
+ DateTime.instance_method(:min).should == DateTime.instance_method(:minute)
+ end
end
diff --git a/spec/ruby/library/datetime/minute_spec.rb b/spec/ruby/library/datetime/minute_spec.rb
index acdfeda345..6e99752de7 100644
--- a/spec/ruby/library/datetime/minute_spec.rb
+++ b/spec/ruby/library/datetime/minute_spec.rb
@@ -1,6 +1,40 @@
require_relative '../../spec_helper'
-require_relative 'shared/min'
+require 'date'
-describe "DateTime.minute" do
- it_behaves_like :datetime_min, :minute
+describe "DateTime#minute" do
+ it "returns 0 if no argument is passed" do
+ DateTime.new.minute.should == 0
+ end
+
+ it "returns the minute passed as argument" do
+ new_datetime(minute: 5).minute.should == 5
+ end
+
+ it "adds 60 to negative minutes" do
+ new_datetime(minute: -20).minute.should == 40
+ end
+
+ it "raises an error for Rational" do
+ -> { new_datetime minute: 5 + Rational(1,2) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for Float" do
+ -> { new_datetime minute: 5.5 }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for Rational" do
+ -> { new_datetime(hour: 2 + Rational(1,2)) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the minute is smaller than -60" do
+ -> { new_datetime(minute: -61) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the minute is greater or equal than 60" do
+ -> { new_datetime(minute: 60) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for minute fractions smaller than -60" do
+ -> { new_datetime(minute: -60 - Rational(1,2))}.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/library/datetime/new_spec.rb b/spec/ruby/library/datetime/new_spec.rb
index 6a4dced384..2b3c3f156c 100644
--- a/spec/ruby/library/datetime/new_spec.rb
+++ b/spec/ruby/library/datetime/new_spec.rb
@@ -47,6 +47,6 @@ describe "DateTime.new" do
end
it "raises an error on invalid arguments" do
- -> { new_datetime(minute: 999) }.should raise_error(ArgumentError)
+ -> { new_datetime(minute: 999) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/datetime/now_spec.rb b/spec/ruby/library/datetime/now_spec.rb
index 9f22153c15..5c0411c2be 100644
--- a/spec/ruby/library/datetime/now_spec.rb
+++ b/spec/ruby/library/datetime/now_spec.rb
@@ -3,7 +3,7 @@ require 'date'
describe "DateTime.now" do
it "creates an instance of DateTime" do
- DateTime.now.should be_an_instance_of(DateTime)
+ DateTime.now.should.instance_of?(DateTime)
end
it "sets the current date" do
diff --git a/spec/ruby/library/datetime/parse_spec.rb b/spec/ruby/library/datetime/parse_spec.rb
index e9bf4e2ed1..0a965273a0 100644
--- a/spec/ruby/library/datetime/parse_spec.rb
+++ b/spec/ruby/library/datetime/parse_spec.rb
@@ -20,7 +20,7 @@ describe "DateTime.parse" do
# Specs using numbers
it "throws an argument error for a single digit" do
- ->{ DateTime.parse("1") }.should raise_error(ArgumentError)
+ ->{ DateTime.parse("1") }.should.raise(ArgumentError)
end
it "parses DD as month day number" do
@@ -54,23 +54,23 @@ describe "DateTime.parse" do
end
it "throws an argument error for invalid month values" do
- ->{DateTime.parse("2012-13-08T15:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-13-08T15:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid day values" do
- ->{DateTime.parse("2012-12-32T15:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-12-32T15:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid hour values" do
- ->{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-12-31T25:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid minute values" do
- ->{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-12-31T25:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid second values" do
- ->{DateTime.parse("2012-11-08T15:43:61")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-11-08T15:43:61")}.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/datetime/rfc2822_spec.rb b/spec/ruby/library/datetime/rfc2822_spec.rb
index 83f7fa8d5b..11b79a1e84 100644
--- a/spec/ruby/library/datetime/rfc2822_spec.rb
+++ b/spec/ruby/library/datetime/rfc2822_spec.rb
@@ -5,6 +5,6 @@ describe "DateTime.rfc2822" do
it "needs to be reviewed for spec completeness"
it "raises DateError if passed nil" do
- -> { DateTime.rfc2822(nil) }.should raise_error(Date::Error, "invalid date")
+ -> { DateTime.rfc2822(nil) }.should.raise(Date::Error, "invalid date")
end
end
diff --git a/spec/ruby/library/datetime/sec_spec.rb b/spec/ruby/library/datetime/sec_spec.rb
index f681283c8e..f8a8b4646e 100644
--- a/spec/ruby/library/datetime/sec_spec.rb
+++ b/spec/ruby/library/datetime/sec_spec.rb
@@ -1,6 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'shared/sec'
+require 'date'
-describe "DateTime.sec" do
- it_behaves_like :datetime_sec, :sec
+describe "DateTime#sec" do
+ it "is an alias of DateTime#second" do
+ DateTime.instance_method(:sec).should == DateTime.instance_method(:second)
+ end
end
diff --git a/spec/ruby/library/datetime/second_fraction_spec.rb b/spec/ruby/library/datetime/second_fraction_spec.rb
index d5393149ba..70f5abf560 100644
--- a/spec/ruby/library/datetime/second_fraction_spec.rb
+++ b/spec/ruby/library/datetime/second_fraction_spec.rb
@@ -2,5 +2,7 @@ require_relative '../../spec_helper'
require 'date'
describe "DateTime#second_fraction" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of DateTime#sec_fraction" do
+ DateTime.instance_method(:second_fraction).should == DateTime.instance_method(:sec_fraction)
+ end
end
diff --git a/spec/ruby/library/datetime/second_spec.rb b/spec/ruby/library/datetime/second_spec.rb
index 545c3f9109..9fb1965b73 100644
--- a/spec/ruby/library/datetime/second_spec.rb
+++ b/spec/ruby/library/datetime/second_spec.rb
@@ -1,6 +1,45 @@
require_relative '../../spec_helper'
-require_relative 'shared/sec'
+require 'date'
describe "DateTime#second" do
- it_behaves_like :datetime_sec, :second
+ it "returns 0 seconds if passed no arguments" do
+ d = DateTime.new
+ d.second.should == 0
+ end
+
+ it "returns the seconds passed in the arguments" do
+ new_datetime(second: 5).second.should == 5
+ end
+
+ it "adds 60 to negative values" do
+ new_datetime(second: -20).second.should == 40
+ end
+
+ it "returns the absolute value of a Rational" do
+ new_datetime(second: 5 + Rational(1,2)).second.should == 5
+ end
+
+ it "returns the absolute value of a float" do
+ new_datetime(second: 5.5).second.should == 5
+ end
+
+ it "raises an error when minute is given as a rational" do
+ -> { new_datetime(minute: 5 + Rational(1,2)) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the second is smaller than -60" do
+ -> { new_datetime(second: -61) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the second is greater or equal than 60" do
+ -> { new_datetime(second: 60) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for second fractions smaller than -60" do
+ -> { new_datetime(second: -60 - Rational(1,2))}.should.raise(ArgumentError)
+ end
+
+ it "takes a second fraction near 60" do
+ new_datetime(second: 59 + Rational(1,2)).second.should == 59
+ end
end
diff --git a/spec/ruby/library/datetime/shared/min.rb b/spec/ruby/library/datetime/shared/min.rb
deleted file mode 100644
index a35b839281..0000000000
--- a/spec/ruby/library/datetime/shared/min.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'date'
-
-describe :datetime_min, shared: true do
- it "returns 0 if no argument is passed" do
- DateTime.new.send(@method).should == 0
- end
-
- it "returns the minute passed as argument" do
- new_datetime(minute: 5).send(@method).should == 5
- end
-
- it "adds 60 to negative minutes" do
- new_datetime(minute: -20).send(@method).should == 40
- end
-
- it "raises an error for Rational" do
- -> { new_datetime minute: 5 + Rational(1,2) }.should raise_error(ArgumentError)
- end
-
- it "raises an error for Float" do
- -> { new_datetime minute: 5.5 }.should raise_error(ArgumentError)
- end
-
- it "raises an error for Rational" do
- -> { new_datetime(hour: 2 + Rational(1,2)) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the minute is smaller than -60" do
- -> { new_datetime(minute: -61) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the minute is greater or equal than 60" do
- -> { new_datetime(minute: 60) }.should raise_error(ArgumentError)
- end
-
- it "raises an error for minute fractions smaller than -60" do
- -> { new_datetime(minute: -60 - Rational(1,2))}.should(
- raise_error(ArgumentError))
- end
-end
diff --git a/spec/ruby/library/datetime/shared/sec.rb b/spec/ruby/library/datetime/shared/sec.rb
deleted file mode 100644
index 60009213aa..0000000000
--- a/spec/ruby/library/datetime/shared/sec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require 'date'
-
-describe :datetime_sec, shared: true do
- it "returns 0 seconds if passed no arguments" do
- d = DateTime.new
- d.send(@method).should == 0
- end
-
- it "returns the seconds passed in the arguments" do
- new_datetime(second: 5).send(@method).should == 5
- end
-
- it "adds 60 to negative values" do
- new_datetime(second: -20).send(@method).should == 40
- end
-
- it "returns the absolute value of a Rational" do
- new_datetime(second: 5 + Rational(1,2)).send(@method).should == 5
- end
-
- it "returns the absolute value of a float" do
- new_datetime(second: 5.5).send(@method).should == 5
- end
-
- it "raises an error when minute is given as a rational" do
- -> { new_datetime(minute: 5 + Rational(1,2)) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the second is smaller than -60" do
- -> { new_datetime(second: -61) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the second is greater or equal than 60" do
- -> { new_datetime(second: 60) }.should raise_error(ArgumentError)
- end
-
- it "raises an error for second fractions smaller than -60" do
- -> { new_datetime(second: -60 - Rational(1,2))}.should(
- raise_error(ArgumentError))
- end
-
- it "takes a second fraction near 60" do
- new_datetime(second: 59 + Rational(1,2)).send(@method).should == 59
- end
-end
diff --git a/spec/ruby/library/datetime/to_date_spec.rb b/spec/ruby/library/datetime/to_date_spec.rb
index 48c05e7fed..31ccf5ae98 100644
--- a/spec/ruby/library/datetime/to_date_spec.rb
+++ b/spec/ruby/library/datetime/to_date_spec.rb
@@ -4,7 +4,7 @@ require 'date'
describe "DateTime#to_date" do
it "returns an instance of Date" do
dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
- dt.to_date.should be_kind_of(Date)
+ dt.to_date.should.is_a?(Date)
end
it "maintains the same year" do
diff --git a/spec/ruby/library/datetime/to_s_spec.rb b/spec/ruby/library/datetime/to_s_spec.rb
index 175fb807f4..ed0746f42b 100644
--- a/spec/ruby/library/datetime/to_s_spec.rb
+++ b/spec/ruby/library/datetime/to_s_spec.rb
@@ -4,7 +4,7 @@ require 'date'
describe "DateTime#to_s" do
it "returns a new String object" do
dt = DateTime.new(2012, 12, 24, 1, 2, 3, "+03:00")
- dt.to_s.should be_kind_of(String)
+ dt.to_s.should.is_a?(String)
end
it "maintains timezone regardless of local time" do
diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb
index 58bb363653..a3ffc019fb 100644
--- a/spec/ruby/library/datetime/to_time_spec.rb
+++ b/spec/ruby/library/datetime/to_time_spec.rb
@@ -4,7 +4,7 @@ date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
describe "DateTime#to_time" do
it "yields a new Time object" do
- DateTime.now.to_time.should be_kind_of(Time)
+ DateTime.now.to_time.should.is_a?(Time)
end
it "returns a Time representing the same instant" do