Skip to content

Commit 87806c1

Browse files
committed
+ Added skip_until(year, month, day, msg) to allow deferring until a deadline.
+ Added fail_after(year, month, day, msg) to allow time-bombing after a deadline. [git-p4: depot-paths = "//src/minitest/dev/": change = 12356]
1 parent fe71663 commit 87806c1

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/minitest/assertions.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,16 @@ def exception_details e, msg
578578
end
579579

580580
##
581-
# Fails with +msg+
581+
# Fails after a given date (in the local time zone). This allows
582+
# you to put time-bombs in your tests if you need to keep
583+
# something around until a later date lest you forget about it.
584+
585+
def fail_after y,m,d,msg
586+
flunk msg if Time.now > Time.local(y, m, d)
587+
end
588+
589+
##
590+
# Fails with +msg+.
582591

583592
def flunk msg = nil
584593
msg ||= "Epic Fail!"
@@ -765,6 +774,18 @@ def skip msg = nil, bt = caller
765774
raise Minitest::Skip, msg, bt
766775
end
767776

777+
##
778+
# Skips the current run until a given date (in the local time
779+
# zone). This allows you to put some fixes on hold until a later
780+
# date, but still holds you accountable and prevents you from
781+
# forgetting it.
782+
783+
def skip_until y,m,d,msg
784+
skip msg if Time.now < Time.local(y, m, d)
785+
where = caller.first.split(/:/, 3).first(2).join ":"
786+
warn "Stale skip_until %p at %s" % [msg, where]
787+
end
788+
768789
##
769790
# Was this testcase skipped? Meant for #teardown.
770791

test/minitest/test_minitest_assertions.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,19 @@ def test_epsilon_consistency
988988
end
989989
end
990990

991+
def test_fail_after
992+
t = Time.now
993+
y, m, d = t.year, t.month, t.day
994+
995+
assert_silent do
996+
@tc.fail_after y, m, d+1, "remove the deprecations"
997+
end
998+
999+
assert_triggered "remove the deprecations" do
1000+
@tc.fail_after y, m, d, "remove the deprecations"
1001+
end
1002+
end
1003+
9911004
def test_flunk
9921005
assert_triggered "Epic Fail!" do
9931006
@tc.flunk
@@ -1199,6 +1212,21 @@ def test_skip
11991212
end
12001213
end
12011214

1215+
def test_skip_until
1216+
@assertion_count = 0
1217+
1218+
t = Time.now
1219+
y, m, d = t.year, t.month, t.day
1220+
1221+
assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
1222+
@tc.skip_until y, m, d, "not yet"
1223+
end
1224+
1225+
assert_triggered "not ready yet", Minitest::Skip do
1226+
@tc.skip_until y, m, d+1, "not ready yet"
1227+
end
1228+
end
1229+
12021230
def util_msg exp, act, msg = nil
12031231
s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
12041232
s = "#{msg}.\n#{s}" if msg

0 commit comments

Comments
 (0)