Last active
August 29, 2015 14:14
-
-
Save stretchkennedy/3b23722a2c945c99f3ba to your computer and use it in GitHub Desktop.
Create a class which will be equal to any of the passed-in arguments.
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
# USAGE: expect(some_object).to eq either(String, 5, { this: :hash }, @something_else) | |
def either *objs | |
Class.new(Object) do | |
@objs = objs | |
def self.===(other) | |
@objs.reduce(false) do |memo, obj| | |
memo ||= JsonExpressions::Matcher.new(obj).match(other) | |
end | |
end | |
def self.inspect | |
"either(#{@objs.map(&:inspect).join(', ')})" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment