diff --git a/lib/minitest/spec.rb b/lib/minitest/spec.rb index 07eeb3a0..738b74e0 100644 --- a/lib/minitest/spec.rb +++ b/lib/minitest/spec.rb @@ -8,6 +8,9 @@ def infect_an_assertion meth, new_name, dont_flip = false # :nodoc: # warn "%-22p -> %p %p" % [meth, new_name, dont_flip] self.class_eval <<-EOM, __FILE__, __LINE__ + 1 def #{new_name} *args + where = Minitest.filter_backtrace(caller).first + where = where.split(/:in /, 2).first # clean up noise + warn "DEPRECATED: global use of #{new_name} from #\{where}. Use _(obj).#{new_name} instead. This will fail in Minitest 6." Minitest::Expectation.new(self, Minitest::Spec.current).#{new_name}(*args) end EOM diff --git a/test/minitest/test_minitest_spec.rb b/test/minitest/test_minitest_spec.rb index 3ce31e30..2e108d9c 100644 --- a/test/minitest/test_minitest_spec.rb +++ b/test/minitest/test_minitest_spec.rb @@ -535,6 +535,18 @@ def assert_triggered expected = "blah", klass = Minitest::Assertion assert_equal "Calling #must_equal outside of test.", e.message end + + it "deprecates expectation used without _" do + skip "N/A" if ENV["MT_NO_EXPECTATIONS"] + + @assertion_count += 3 + + exp = /DEPRECATED: global use of must_equal from/ + + assert_output "", exp do + (1 + 1).must_equal 2 + end + end end it "needs to verify throw" do