Created
October 24, 2013 02:55
-
-
Save anonymous/7130551 to your computer and use it in GitHub Desktop.
Simple method to assert something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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