Created
May 11, 2010 10:25
-
-
Save jarib/397159 to your computer and use it in GitHub Desktop.
This file contains 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
class Object | |
def should(matcher) | |
if matcher.matches? self | |
# ok | |
else | |
raise matcher.positive_failure_message | |
end | |
end | |
def should_not(matcher) | |
if matcher.matches? self | |
raise matcher.negative_failure_message | |
else | |
# ok | |
end | |
end | |
end | |
class BeEqualToMatcher | |
def initialize(other) | |
@other = other | |
end | |
def matches?(original) | |
@original = original | |
@other == original | |
end | |
def negative_failure_message | |
"expected #{@original.inspect} to not equal #{@other.inspect}" | |
end | |
def positive_failure_message | |
"expected #{@original.inspect} to equal #{@other.inspect}" | |
end | |
end | |
def be_equal_to(other) | |
BeEqualToMatcher.new(other) | |
end | |
string = 'hei' | |
string.should be_equal_to('heiasdasd') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment