Skip to content

Instantly share code, notes, and snippets.

@jarib
Created May 11, 2010 10:25
Show Gist options
  • Save jarib/397159 to your computer and use it in GitHub Desktop.
Save jarib/397159 to your computer and use it in GitHub Desktop.
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