Test Assertions

July 29, 2025 · View on GitHub

Quokka rewrites test assertions to use the more idiomatic assert and refute macros where semantically appropriate.

Transformations

assert notrefute

Rewrites negated assertions to use the refute macro:

# Before
assert not user.status == :active
assert not Process.alive?(pid)

# After
refute user.status == :active
refute Process.alive?(pid)

assert !refute

Rewrites bang-negated assertions to use the refute macro:

# Before
assert !user.active
assert !valid?
assert !result

# After
refute user.active
refute valid?
refute result

refute notassert

Rewrites negated refutations to use the assert macro:

# Before
refute not user.status == :active
refute not Process.alive?(pid)

# After
assert user.status == :active
assert Process.alive?(pid)

refute !assert

Rewrites bang-negated refutations to use the assert macro:

# Before
refute !user.active
refute !valid?
refute !result

# After
assert user.active
assert valid?
assert result

Membership Testing

A common pattern in tests is checking that elements are not in collections:

# Before
assert elem not in my_list
assert not (user in banned_users)
assert !(key in forbidden_keys)

# After
refute elem in my_list
refute user in banned_users
refute key in forbidden_keys