forked from rspec/rspec-expectations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
has.rb
35 lines (25 loc) · 754 Bytes
/
has.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module RSpec
module Matchers
class Has
def initialize(expected, *args)
@expected, @args = expected, args
end
def matches?(actual)
actual.__send__(predicate(@expected), *@args)
end
def failure_message_for_should
"expected ##{predicate(@expected)}(#{@args[0].inspect}) to return true, got false"
end
def failure_message_for_should_not
"expected ##{predicate(@expected)}(#{@args[0].inspect}) to return false, got true"
end
def description
"have key #{@args[0].inspect}"
end
private
def predicate(sym)
"#{sym.to_s.sub("have_","has_")}?".to_sym
end
end
end
end