Skip to content

Instantly share code, notes, and snippets.

Created October 24, 2013 02:55
Show Gist options
  • Save anonymous/7130551 to your computer and use it in GitHub Desktop.
Save anonymous/7130551 to your computer and use it in GitHub Desktop.
Simple method to assert something
module Assert
class AssertFailedException < Exception
end
def assert!(object, method, expected_value)
# If method returns a boolean and expected value is nil, assume that
# truthy passes the assertion
result = object.send(method)
if result != expected_value
raise new Assert::AssertFailedException("#{object} expected #{method} to be #{expected_value} but was #{result}"
end
end
end
Object.send(:include, Assert)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment