Sample
minitest 6.0.6: In Minitest 6.0.6, assert_same forbids nil to enforce assert_nil, assert_raises validates that exception targets are Modules, and predicate assertions invoke assert_respond_to with include_all:true
Verified sample for gem minitest 6.0.6: In Minitest 6.0.6, assert_same forbids nil to enforce assert_nil, assert_raises validates that exception targets are…
sha256:23277ff641ae68ddfdfa1203f7a58ada15b21197fe9d08cb1c4750464890e536
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
ruby linux x64 ruby ruby bundler
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-17 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-18 |
Case
HOW- Goal
- In Minitest 6.0.6, assert_same forbids nil to enforce assert_nil, assert_raises validates that exception targets are Modules, and predicate assertions invoke assert_respond_to with include_all:true
- Packages
- Symbols
-
- Minitest::Assertions#assert_same
- Minitest::Assertions#assert_raises
- Minitest::Assertions#assert_predicate
- Minitest::Assertions#refute_predicate
- Minitest::Assertions#assert_nil
- Minitest::Assertions#refute_nil
- Minitest::Assertions#message
- Environment
- ruby
- Created
- 2026-08-17T18:03:47Z
Contract
- assert_same(nil, value) raises Minitest::Assertion with "Use assert_nil if expecting nil" even when comparing nil to nil, enforcing explicit use of assert_nil for nil checks
- assert_raises validates that all exception targets are Modules before executing the block, raising TypeError when passed an exception instance or non-Module argument
- assert_predicate and refute_predicate call assert_respond_to with include_all: true, incrementing the test assertion count by 2 and allowing private predicate methods to be tested directly
- assert_nil and refute_nil compare objects using nil == obj, safely evaluating BasicObject instances without raising NoMethodError for missing nil? methods
- Passing a Proc as a custom failure message completely overrides default assertion output without appending default diffs or punctuation
Files
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- test/contract.rb
Source
source "https://rubygems.org"
gem "minitest", "= 6.0.6"
GEM
remote: https://rubygems.org/
specs:
drb (2.2.1)
minitest (6.0.6)
drb (~> 2.0)
prism (~> 1.5)
prism (1.5.3)
PLATFORMS
ruby
x64-mingw-ucrt
x86_64-linux
x86_64-linux-musl
DEPENDENCIES
minitest (= 6.0.6)
CHECKSUMS
drb (2.2.1) sha256=e9d472bf785f558b96b25358bae115646da0dbfd45107ad858b0bc0d935cb340
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
prism (1.5.3)
BUNDLED WITH
2.6.9
# Minitest 6 Assertion and Error Handling Notes
## Known Solutions Search
A search with `search_known_solution` for `minitest` returned two cached samples:
- `sha256:b46d09ac09a40810f24397605f05ee322446d0b080b89fbb246295977afede04`, which proves `assert_nil` vs `assert_equal(nil, ...)`, `refute_respond_to self, :assert_send`, `assert_output`, `assert_path_exists`, and the removal of built-in `Minitest::Mock`.
- `sha256:0199365007f54358f8e7dc42e65dee893c7de0bcabb962584bf17d58e0e689b3`, which proves `MT_CPU=1` causing `Minitest.parallel_executor` to be `nil` and `parallelize_me!` behaving as a silent no-op.
This project investigates distinct assertion semantics and error handling contracts in Minitest 6: `assert_same` nil rejection, `assert_raises` exception argument validation, predicate assertion counting and private method visibility, `BasicObject` nil checking, and Proc message overrides.
## Pinned Version
- `minitest` version: `6.0.6`
## Observed Behavior
1. **Identity Assertion Forbids Nil (`assert_same`)**:
In Minitest 6, `assert_same(exp, act)` invokes `refute_nil exp` when `nil == exp`. Even when comparing `nil` to `nil` (where `nil.equal?(nil)` evaluates to `true`), `assert_same` raises `Minitest::Assertion` with the message `"Use assert_nil if expecting nil"`. Callers must use `assert_nil` instead.
2. **Strict Module Validation in `assert_raises`**:
`assert_raises(*exp)` inspects all expected exception parameters. Before yielding the target test block, it enforces `raise TypeError, NO_RE_MSG % [exp] unless exp.all? Module`. Passing an exception instance (such as `CustomError.new`) or a non-Module object raises a `TypeError` immediately before the block can execute.
3. **Predicate Assertion Counting and Private Method Dispatch**:
Both `assert_predicate` and `refute_predicate` internally call `assert_respond_to(target, method, include_all: true)` before invoking the predicate with `__send__`. This has two critical effects:
- Each call increments `self.assertions` by 2 (one increment for `assert_respond_to` and one for the predicate assertion).
- Private and protected predicate methods can be tested directly without raising `NoMethodError` because `include_all: true` permits private lookup.
- Non-existent methods fail gracefully via `assert_respond_to` ("Expected ... to respond to #method") rather than crashing with an unhandled `NoMethodError`.
4. **Safe `BasicObject` Nil Comparisons**:
`assert_nil` and `refute_nil` evaluate `nil == obj` rather than `obj.nil?` or `obj == nil`. Because `BasicObject` instances do not implement `Kernel#nil?`, comparing `nil == obj` routes to `NilClass#==` and safely returns `false` without raising `NoMethodError`.
5. **Proc Message Overrides**:
Passing a `Proc` or lambda as the custom failure message to assertion methods (like `assert_equal(exp, act, -> { "custom message" })`) completely replaces the default failure formatting. The proc is returned directly without appending diff text, default failure labels, or trailing punctuation.
## Failure Mode
- Expecting `assert_same(nil, nil)` to pass based on Ruby identity equality fails **loudly** with `Minitest::Assertion: Expected nil to not be nil. Use assert_nil if expecting nil.`.
- Expecting `assert_raises(CustomError.new)` to match the raised instance fails **loudly** with `TypeError: class or module required for rescue clause.` before block evaluation.
{"case":{"believed":"Calling assert_same with nil compares identity using equal? and passes on nil values, while assert_raises accepts exception instances without raising a TypeError","caseId":"case:sha256:67b270afba5fa16a4489991bbd775aee31c67e80e972a7c4c590398860c092f5","contract":["assert_same(nil, value) raises Minitest::Assertion with \"Use assert_nil if expecting nil\" even when comparing nil to nil, enforcing explicit use of assert_nil for nil checks","assert_raises validates that all exception targets are Modules before executing the block, raising TypeError when passed an exception instance or non-Module argument","assert_predicate and refute_predicate call assert_respond_to with include_all: true, incrementing the test assertion count by 2 and allowing private predicate methods to be tested directly","assert_nil and refute_nil compare objects using nil == obj, safely evaluating BasicObject instances without raising NoMethodError for missing nil? methods","Passing a Proc as a custom failure message completely overrides default assertion output without appending default diffs or punctuation"],"goal":"In Minitest 6.0.6, assert_same forbids nil to enforce assert_nil, assert_raises validates that exception targets are Modules, and predicate assertions invoke assert_respond_to with include_all:true","kind":"HOW","packages":["pkg:gem/minitest@6.0.6"],"schemaVersion":1,"symbols":["Minitest::Assertions#assert_same","Minitest::Assertions#assert_raises","Minitest::Assertions#assert_predicate","Minitest::Assertions#refute_predicate","Minitest::Assertions#assert_nil","Minitest::Assertions#refute_nil","Minitest::Assertions#message"]},"contractCommand":["bundle","exec","ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundler","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/minitest@6.0.6"],"schemaVersion":1,"symbols":["Minitest::Assertions#assert_same","Minitest::Assertions#assert_raises","Minitest::Assertions#assert_predicate","Minitest::Assertions#refute_predicate","Minitest::Assertions#assert_nil","Minitest::Assertions#refute_nil","Minitest::Assertions#message"],"verifierAdapter":"rubygems@1"}
require "minitest"
require "minitest/test"
raise "unexpected minitest version" unless Minitest::VERSION == "6.0.6"
Minitest.seed = 42
test_case_class = Class.new(Minitest::Test)
test = test_case_class.new("contract_probe")
# 1. assert_same(nil, value) raises Minitest::Assertion directing callers to assert_nil
assert_same_failed = false
begin
test.assert_same nil, nil
rescue Minitest::Assertion => e
assert_same_failed = true
raise "expected guidance to use assert_nil in message" unless e.message.include?("Use assert_nil if expecting nil")
end
raise "assert_same(nil, nil) should have raised Minitest::Assertion" unless assert_same_failed
# 2. assert_raises validates that all exception targets are Modules, raising TypeError
type_error_raised = false
block_executed = false
begin
test.assert_raises(RuntimeError.new("instance")) { block_executed = true }
rescue TypeError => e
type_error_raised = true
raise "assert_raises should not execute block on invalid target" if block_executed
raise "unexpected TypeError message" unless e.message.include?("class or module required for rescue clause")
end
raise "assert_raises with exception instance should have raised TypeError" unless type_error_raised
# 3. assert_predicate / refute_predicate increment assertions by 2 and support private methods
target_class = Class.new do
private
def internal_ready?
true
end
def internal_blocked?
false
end
end
target = target_class.new
test.assertions = 0
test.assert_predicate target, :internal_ready?
raise "assert_predicate must increment assertions count by 2" unless test.assertions == 2
test.refute_predicate target, :internal_blocked?
raise "refute_predicate must increment assertions count by 2 (total 4)" unless test.assertions == 4
# Missing predicate method triggers assert_respond_to assertion failure rather than NoMethodError
respond_to_failure = false
begin
test.assert_predicate Object.new, :non_existent_predicate?
rescue Minitest::Assertion => e
respond_to_failure = true
raise "expected respond_to failure message" unless e.message.include?("to respond to #non_existent_predicate?")
end
raise "missing method should fail assert_respond_to" unless respond_to_failure
# 4. BasicObject compatibility with assert_nil and refute_nil via `nil == obj`
basic_obj = BasicObject.new
test.refute_nil basic_obj
nil_value = nil
test.assert_nil nil_value
# 5. Proc failure message overrides default output completely
err_str = nil
begin
test.assert_equal 1, 2, "custom label"
rescue Minitest::Assertion => e
err_str = e
end
raise "String message should prepend to diff output" unless err_str.message.include?("custom label.\nExpected: 1\n Actual: 2")
err_proc = nil
begin
test.assert_equal 1, 2, -> { "exact custom proc message" }
rescue Minitest::Assertion => e
err_proc = e
end
raise "Proc message should strictly equal proc output without diff" unless err_proc.message == "exact custom proc message"