-
-
Notifications
You must be signed in to change notification settings - Fork 396
/
be_between.rb
40 lines (32 loc) · 917 Bytes
/
be_between.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
36
37
38
39
40
module RSpec
module Matchers
module BuiltIn
class BeBetween < BaseMatcher
include Composable
def initialize(min, max)
@min, @max = min, max
end
def matches?(actual)
@actual = actual
comparable? and @actual.between?(@min, @max)
end
def failure_message
"expected #{@actual.inspect} to #{description}#{not_comparable_clause}"
end
def failure_message_when_negated
"expected #{@actual.inspect} not to #{description}"
end
def description
"be between #{@min.inspect} and #{@max.inspect} (inclusive)"
end
private
def comparable?
@actual.respond_to?(:between?)
end
def not_comparable_clause
", but #{@actual.inspect} does not respond to `between?`" unless comparable?
end
end
end
end
end