Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 49dc4512db
Fetching contributors…

Cannot retrieve contributors at this time

27 lines (24 sloc) 0.87 kb
module RSpec
module Matchers
module BuiltIn
class Exist < BaseMatcher
def initialize(*expected)
@expected = expected
end
def matches?(actual)
@actual = actual
predicates = [:exist?, :exists?].select { |p| @actual.respond_to?(p) }
existence_values = predicates.map { |p| @actual.send(p, *@expected) }
uniq_truthy_values = existence_values.map { |v| !!v }.uniq
case uniq_truthy_values.size
when 0; raise NoMethodError.new("#{@actual.inspect} does not respond to either #exist? or #exists?")
when 1; existence_values.first
else raise "#exist? and #exists? returned different values:\n\n" +
" exist?: #{existence_values.first}\n" +
"exists?: #{existence_values.last}"
end
end
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.