summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/type/schedule_spec.rb58
1 files changed, 15 insertions, 43 deletions
diff --git a/spec/unit/type/schedule_spec.rb b/spec/unit/type/schedule_spec.rb
index 86b3cdd35..387370fca 100755
--- a/spec/unit/type/schedule_spec.rb
+++ b/spec/unit/type/schedule_spec.rb
@@ -13,14 +13,6 @@ module ScheduleTesting
Time.at(diff)
end
- def month(method, count)
- diff(:hour, 3600 * 24 * 30, method, count)
- end
-
- def week(method, count)
- diff(:hour, 3600 * 24 * 7, method, count)
- end
-
def day(method, count)
diff(:hour, 3600 * 24, method, count)
end
@@ -33,10 +25,6 @@ module ScheduleTesting
diff(:min, 60, method, count)
end
- def sec(method, count)
- diff(:sec, 1, method, count)
- end
-
end
describe Puppet::Type.type(:schedule) do
@@ -194,26 +182,18 @@ describe Puppet::Type.type(:schedule) do
end
it "should match if the times are one minute apart and the current minute is 0" do
- current = Time.now
+ current = Time.utc(2008, 1, 1, 0, 0, 0)
+ previous = Time.utc(2007, 12, 31, 23, 59, 0)
- # Subtract an hour, reset the minute to zero, then add 59 minutes, so we're the previous hour plus 59 minutes.
- previous = (current - 3600 - (current.min * 60) + (59 * 60))
-
- # Now set the "current" time to the zero minute of the current hour.
- now = (current - (current.min * 60))
- Time.stubs(:now).returns(now)
+ Time.stubs(:now).returns(current)
@schedule.match?(previous).should be_true
end
- it "should not match if the times are 58 minutes apart and the current minute is 59" do
- current = Time.now
-
- # reset the minute to zero
- previous = current - (current.min * 60)
+ it "should not match if the times are 59 minutes apart and the current minute is 59" do
+ current = Time.utc(2009, 2, 1, 12, 59, 0)
+ previous = Time.utc(2009, 2, 1, 12, 0, 0)
- # Now set the "current" time to the 59th minute of the current hour.
- now = (current - (current.min * 60) + (59 * 60))
- Time.stubs(:now).returns(now)
+ Time.stubs(:now).returns(current)
@schedule.match?(previous).should be_false
end
end
@@ -258,19 +238,15 @@ describe Puppet::Type.type(:schedule) do
end
it "should match if the previous time is prior to the most recent Sunday" do
- now = Time.now
-
- # Subtract the number days we've progressed into the week, plus one because we're zero-indexed.
- previous = now - (3600 * 24 * (now.wday + 1))
+ now = Time.utc(2010, "nov", 11, 0, 0, 0) # Thursday
+ previous = Time.utc(2010, "nov", 6, 23, 59, 59) # Sat
@schedule.match?(previous).should be_true
end
it "should not match if the previous time is after the most recent Saturday" do
- now = Time.now
-
- # Subtract the number days we've progressed into the week
- previous = now - (3600 * 24 * now.wday)
+ now = Time.utc(2010, "nov", 11, 0, 0, 0) # Thursday
+ previous = Time.utc(2010, "nov", 7, 0, 0, 0) # Sunday
@schedule.match?(previous).should be_false
end
@@ -285,19 +261,15 @@ describe Puppet::Type.type(:schedule) do
end
it "should match when the previous time is prior to the first day of this month" do
- now = Time.now
-
- # Subtract the number days we've progressed into the month
- previous = now - (3600 * 24 * now.day)
+ now = Time.utc(2010, "nov", 8, 00, 59, 59)
+ previous = Time.utc(2010, "oct", 31, 23, 59, 59)
@schedule.match?(previous).should be_true
end
it "should not match when the previous time is after the last day of last month" do
- now = Time.now
-
- # Subtract the number days we've progressed into the month, minus one
- previous = now - (3600 * 24 * (now.day - 1))
+ now = Time.utc(2010, "nov", 8, 00, 59, 59)
+ previous = Time.utc(2010, "nov", 1, 0, 0, 0)
@schedule.match?(previous).should be_false
end