summaryrefslogtreecommitdiff
path: root/spec/ruby/library/date
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/date')
-rw-r--r--spec/ruby/library/date/friday_spec.rb12
-rw-r--r--spec/ruby/library/date/minus_month_spec.rb2
-rw-r--r--spec/ruby/library/date/minus_spec.rb4
-rw-r--r--spec/ruby/library/date/monday_spec.rb8
-rw-r--r--spec/ruby/library/date/next_day_spec.rb10
-rw-r--r--spec/ruby/library/date/next_month_spec.rb15
-rw-r--r--spec/ruby/library/date/prev_day_spec.rb6
-rw-r--r--spec/ruby/library/date/prev_month_spec.rb15
-rw-r--r--spec/ruby/library/date/saturday_spec.rb8
-rw-r--r--spec/ruby/library/date/sunday_spec.rb8
-rw-r--r--spec/ruby/library/date/thursday_spec.rb8
-rw-r--r--spec/ruby/library/date/today_spec.rb10
-rw-r--r--spec/ruby/library/date/tuesday_spec.rb8
-rw-r--r--spec/ruby/library/date/wday_spec.rb5
-rw-r--r--spec/ruby/library/date/wednesday_spec.rb8
15 files changed, 116 insertions, 11 deletions
diff --git a/spec/ruby/library/date/friday_spec.rb b/spec/ruby/library/date/friday_spec.rb
new file mode 100644
index 0000000000..369b943419
--- /dev/null
+++ b/spec/ruby/library/date/friday_spec.rb
@@ -0,0 +1,12 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#friday?" do
+ it "should be friday" do
+ Date.new(2000, 1, 7).friday?.should be_true
+ end
+
+ it "should not be friday" do
+ Date.new(2000, 1, 8).friday?.should be_false
+ end
+end
diff --git a/spec/ruby/library/date/minus_month_spec.rb b/spec/ruby/library/date/minus_month_spec.rb
index b6b20c5578..fbe5cb8593 100644
--- a/spec/ruby/library/date/minus_month_spec.rb
+++ b/spec/ruby/library/date/minus_month_spec.rb
@@ -3,7 +3,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe "Date#<<" do
- it "substracts a number of months from a date" do
+ it "subtracts a number of months from a date" do
d = Date.civil(2007,2,27) << 10
d.should == Date.civil(2006, 4, 27)
end
diff --git a/spec/ruby/library/date/minus_spec.rb b/spec/ruby/library/date/minus_spec.rb
index 09da595872..fd7f3fd14c 100644
--- a/spec/ruby/library/date/minus_spec.rb
+++ b/spec/ruby/library/date/minus_spec.rb
@@ -3,12 +3,12 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe "Date#-" do
- it "substracts a number of days from a Date" do
+ it "subtracts a number of days from a Date" do
d = Date.civil(2007, 5 ,2) - 13
d.should == Date.civil(2007, 4, 19)
end
- it "substracts a negative number of days from a Date" do
+ it "subtracts a negative number of days from a Date" do
d = Date.civil(2007, 4, 19).-(-13)
d.should == Date.civil(2007, 5 ,2)
end
diff --git a/spec/ruby/library/date/monday_spec.rb b/spec/ruby/library/date/monday_spec.rb
new file mode 100644
index 0000000000..f7d968b6d6
--- /dev/null
+++ b/spec/ruby/library/date/monday_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#monday?" do
+ it "should be monday" do
+ Date.new(2000, 1, 3).monday?.should be_true
+ end
+end
diff --git a/spec/ruby/library/date/next_day_spec.rb b/spec/ruby/library/date/next_day_spec.rb
index 1ccb4df257..795bfecf0a 100644
--- a/spec/ruby/library/date/next_day_spec.rb
+++ b/spec/ruby/library/date/next_day_spec.rb
@@ -3,8 +3,12 @@ require 'date'
describe "Date#next_day" do
it "returns the next day" do
- d = Date.new(2000, 1, 5)
- d1 = Date.new(2000, 1, 4).next_day
- d1.should == d
+ d = Date.new(2000, 1, 4).next_day
+ d.should == Date.new(2000, 1, 5)
+ end
+
+ it "returns three days later across months" do
+ d = Date.new(2000, 1, 30).next_day(3)
+ d.should == Date.new(2000, 2, 2)
end
end
diff --git a/spec/ruby/library/date/next_month_spec.rb b/spec/ruby/library/date/next_month_spec.rb
index 22699a39a5..9becd7e37f 100644
--- a/spec/ruby/library/date/next_month_spec.rb
+++ b/spec/ruby/library/date/next_month_spec.rb
@@ -11,4 +11,19 @@ describe "Date#next_month" do
d = Date.new(2000, 7, 1).next_month(3)
d.should == Date.new(2000, 10, 1)
end
+
+ it "returns three months later across years" do
+ d = Date.new(2000, 12, 1).next_month(3)
+ d.should == Date.new(2001, 3, 1)
+ end
+
+ it "returns last day of month two months later" do
+ d = Date.new(2000, 1, 31).next_month(2)
+ d.should == Date.new(2000, 3, 31)
+ end
+
+ it "returns last day of next month when same day does not exist" do
+ d = Date.new(2001, 1, 30).next_month
+ d.should == Date.new(2001, 2, 28)
+ end
end
diff --git a/spec/ruby/library/date/prev_day_spec.rb b/spec/ruby/library/date/prev_day_spec.rb
index 8a42824154..149bfe9fa9 100644
--- a/spec/ruby/library/date/prev_day_spec.rb
+++ b/spec/ruby/library/date/prev_day_spec.rb
@@ -7,8 +7,8 @@ describe "Date#prev_day" do
d.should == Date.new(2000, 7, 1)
end
- it "returns three days ago" do
- d = Date.new(2000, 7, 4).prev_day(3)
- d.should == Date.new(2000, 7, 1)
+ it "returns three days ago across months" do
+ d = Date.new(2000, 7, 2).prev_day(3)
+ d.should == Date.new(2000, 6, 29)
end
end
diff --git a/spec/ruby/library/date/prev_month_spec.rb b/spec/ruby/library/date/prev_month_spec.rb
index eaf7f67ee0..440c17ffc9 100644
--- a/spec/ruby/library/date/prev_month_spec.rb
+++ b/spec/ruby/library/date/prev_month_spec.rb
@@ -11,4 +11,19 @@ describe "Date#prev_month" do
d = Date.new(2000, 10, 1).prev_month(3)
d.should == Date.new(2000, 7, 1)
end
+
+ it "returns three months ago across years" do
+ d = Date.new(2000, 1, 1).prev_month(3)
+ d.should == Date.new(1999, 10, 1)
+ end
+
+ it "returns last day of month two months ago" do
+ d = Date.new(2000, 3, 31).prev_month(2)
+ d.should == Date.new(2000, 1, 31)
+ end
+
+ it "returns last day of previous month when same day does not exist" do
+ d = Date.new(2001, 3, 30).prev_month
+ d.should == Date.new(2001, 2, 28)
+ end
end
diff --git a/spec/ruby/library/date/saturday_spec.rb b/spec/ruby/library/date/saturday_spec.rb
new file mode 100644
index 0000000000..1360050a69
--- /dev/null
+++ b/spec/ruby/library/date/saturday_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#saturday?" do
+ it "should be saturday" do
+ Date.new(2000, 1, 1).saturday?.should be_true
+ end
+end
diff --git a/spec/ruby/library/date/sunday_spec.rb b/spec/ruby/library/date/sunday_spec.rb
new file mode 100644
index 0000000000..d805006264
--- /dev/null
+++ b/spec/ruby/library/date/sunday_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#sunday?" do
+ it "should be sunday" do
+ Date.new(2000, 1, 2).sunday?.should be_true
+ end
+end
diff --git a/spec/ruby/library/date/thursday_spec.rb b/spec/ruby/library/date/thursday_spec.rb
new file mode 100644
index 0000000000..a59ca3f6cf
--- /dev/null
+++ b/spec/ruby/library/date/thursday_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#thursday?" do
+ it "should be thursday" do
+ Date.new(2000, 1, 6).thursday?.should be_true
+ end
+end
diff --git a/spec/ruby/library/date/today_spec.rb b/spec/ruby/library/date/today_spec.rb
index 09e8ed6006..d487be089f 100644
--- a/spec/ruby/library/date/today_spec.rb
+++ b/spec/ruby/library/date/today_spec.rb
@@ -2,5 +2,13 @@ require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
describe "Date.today" do
- it "needs to be reviewed for spec completeness"
+ it "returns a Date object" do
+ Date.today.should be_kind_of Date
+ end
+
+ it "sets Date object to the current date" do
+ today = Date.today
+ now = Time.now
+ (now - today.to_time).should be_close(0.0, 24 * 60 * 60)
+ end
end
diff --git a/spec/ruby/library/date/tuesday_spec.rb b/spec/ruby/library/date/tuesday_spec.rb
new file mode 100644
index 0000000000..10ed6755d1
--- /dev/null
+++ b/spec/ruby/library/date/tuesday_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#tuesday?" do
+ it "should be tuesday" do
+ Date.new(2000, 1, 4).tuesday?.should be_true
+ end
+end
diff --git a/spec/ruby/library/date/wday_spec.rb b/spec/ruby/library/date/wday_spec.rb
index 1d40b0c96c..7303423123 100644
--- a/spec/ruby/library/date/wday_spec.rb
+++ b/spec/ruby/library/date/wday_spec.rb
@@ -2,5 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
describe "Date#wday" do
- it "needs to be reviewed for spec completeness"
+ it "returns the week day as a number starting with Sunday as 0" do
+ w = Date.new(2000, 1, 1).wday
+ w.should == 6
+ end
end
diff --git a/spec/ruby/library/date/wednesday_spec.rb b/spec/ruby/library/date/wednesday_spec.rb
new file mode 100644
index 0000000000..99478f21c2
--- /dev/null
+++ b/spec/ruby/library/date/wednesday_spec.rb
@@ -0,0 +1,8 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "Date#wednesday?" do
+ it "should be wednesday" do
+ Date.new(2000, 1, 5).wednesday?.should be_true
+ end
+end