Skip to content

Commit

Permalink
+ Added skip_until(year, month, day, msg) to allow deferring until a …
Browse files Browse the repository at this point in the history
…deadline.

+ Added fail_after(year, month, day, msg) to allow time-bombing after a deadline.

[git-p4: depot-paths = "//src/minitest/dev/": change = 12356]
  • Loading branch information
zenspider committed Oct 20, 2019
1 parent fe71663 commit 87806c1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,16 @@ def exception_details e, msg
end

##
# Fails with +msg+
# Fails after a given date (in the local time zone). This allows
# you to put time-bombs in your tests if you need to keep
# something around until a later date lest you forget about it.

def fail_after y,m,d,msg
flunk msg if Time.now > Time.local(y, m, d)
end

##
# Fails with +msg+.

def flunk msg = nil
msg ||= "Epic Fail!"
Expand Down Expand Up @@ -765,6 +774,18 @@ def skip msg = nil, bt = caller
raise Minitest::Skip, msg, bt
end

##
# Skips the current run until a given date (in the local time
# zone). This allows you to put some fixes on hold until a later
# date, but still holds you accountable and prevents you from
# forgetting it.

def skip_until y,m,d,msg
skip msg if Time.now < Time.local(y, m, d)
where = caller.first.split(/:/, 3).first(2).join ":"
warn "Stale skip_until %p at %s" % [msg, where]
end

##
# Was this testcase skipped? Meant for #teardown.

Expand Down
28 changes: 28 additions & 0 deletions test/minitest/test_minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,19 @@ def test_epsilon_consistency
end
end

def test_fail_after
t = Time.now
y, m, d = t.year, t.month, t.day

assert_silent do
@tc.fail_after y, m, d+1, "remove the deprecations"
end

assert_triggered "remove the deprecations" do
@tc.fail_after y, m, d, "remove the deprecations"
end
end

def test_flunk
assert_triggered "Epic Fail!" do
@tc.flunk
Expand Down Expand Up @@ -1199,6 +1212,21 @@ def test_skip
end
end

def test_skip_until
@assertion_count = 0

t = Time.now
y, m, d = t.year, t.month, t.day

assert_output "", /Stale skip_until \"not yet\" at .*?:\d+$/ do
@tc.skip_until y, m, d, "not yet"
end

assert_triggered "not ready yet", Minitest::Skip do
@tc.skip_until y, m, d+1, "not ready yet"
end
end

def util_msg exp, act, msg = nil
s = "Expected: #{exp.inspect}\n Actual: #{act.inspect}"
s = "#{msg}.\n#{s}" if msg
Expand Down

0 comments on commit 87806c1

Please sign in to comment.