Skip to content

Commit

Permalink
+ Fail gracefully when expectation used outside of it.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 11568]
  • Loading branch information
zenspider committed Mar 6, 2018
1 parent 3f32f02 commit 879dc1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def #{new_name} *args

Minitest::Expectation.class_eval <<-EOM, __FILE__, __LINE__ + 1
def #{new_name} *args
raise "Calling ##{new_name} outside of test." unless ctx
case
when #{!!dont_flip} then
ctx.#{meth}(target, *args)
Expand Down
20 changes: 19 additions & 1 deletion test/minitest/test_minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,30 @@ def assert_triggered expected = "blah", klass = Minitest::Assertion

it "can NOT use must_equal in a thread. It must use expect in a thread" do
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
assert_raises NoMethodError do
assert_raises RuntimeError do
capture_io do
Thread.new { (1 + 1).must_equal 2 }.join
end
end
end

it "fails gracefully when expectation used outside of `it`" do
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]

@assertion_count += 1

e = assert_raises RuntimeError do
capture_io do
Thread.new { # forces ctx to be nil
describe("woot") do
(1 + 1).must_equal 2
end
}.join
end
end

assert_equal "Calling #must_equal outside of test.", e.message
end
end

it "needs to verify throw" do
Expand Down

0 comments on commit 879dc1c

Please sign in to comment.