There are many assert functions if you are writing tests. But for assertiona in the main code, there aren't any and you can roll your own easily.
Add something like this to environment.rb
:
class AssertFailure < Exception
end
def assert(message = 'assertion failed')
unless block_given? and yield
raise message
end
end
and make it a no-op in your environments/production.rb
so there is minimal overhead
def assert(message = 'assertion failed')
end
Then, in your code, you can assert to your heart's content:
assert { value == expected_value }
assert('value was not what was expected') { value == expected_value }
If value
does not equal expected_value
and you aren't running in production, an exception will be raised.