Module: Minitest::AssertionTests
- Defined in:
- lib/minitest/assertion_tests.rb
Overview
Use Minitest::AssertionTests to test assertions for Minitest.
describe Minitest::BonusAssertions do
include Minitest::AssertionTests
it 'be triggered for false or nil' do
assert_expected_assertions 2 do
assert_assertion_triggered '<true> expected but was false.' do
tc.assert_true false
end
assert_assertion_triggered '<true> expected but was nil.' do
tc.assert_true nil
end
end
end
end
Instance Attribute Summary collapse
-
#spec ⇒ Object
readonly
The test spec to use for the expectation under test.
-
#tc ⇒ Object
readonly
The test case to use for the assertion under test.
Instance Method Summary collapse
-
#assert_assertion_triggered(expected, klass = Minitest::Assertion) ⇒ Object
Specify that the assertion was expected to fail with the resulting message.
-
#assert_expected_assertions(expected = 1) ⇒ Object
Specify the number of assertions that should be called during the test under this block.
-
#setup ⇒ Object
:nodoc:.
Instance Attribute Details
#spec ⇒ Object (readonly)
The test spec to use for the expectation under test.
23 24 25 |
# File 'lib/minitest/assertion_tests.rb', line 23 def spec @spec end |
#tc ⇒ Object (readonly)
The test case to use for the assertion under test.
21 22 23 |
# File 'lib/minitest/assertion_tests.rb', line 21 def tc @tc end |
Instance Method Details
#assert_assertion_triggered(expected, klass = Minitest::Assertion) ⇒ Object
Specify that the assertion was expected to fail with the resulting message.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/minitest/assertion_tests.rb', line 45 def assert_assertion_triggered expected, klass = Minitest::Assertion e = assert_raises(klass) do yield end msg = e..sub(/(---Backtrace---).*/m, '\1') msg.gsub!(/\(oid=[-0-9]+\)/, '(oid=N)') msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform assert_equal expected, msg end |
#assert_expected_assertions(expected = 1) ⇒ Object
Specify the number of assertions that should be called during the test under this block. Most tests should be wrapped in this assertion.
36 37 38 39 40 41 42 |
# File 'lib/minitest/assertion_tests.rb', line 36 def assert_expected_assertions expected = 1 yield ensure actual = tc.assertions + spec.assertions assert_equal expected, actual, "expected #{expected} assertions to be " + "fired during the test, not #{actual}" end |