/
assertions.rb
39 lines (35 loc) · 1.04 KB
/
assertions.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
# frozen_string_literal: true
module TestPuma
module Assertions
def assert_start_with(obj, str, msg = nil)
msg = message(msg) {
"Expected\n#{obj}\nto start with #{str}"
}
assert_respond_to obj, :start_with?
assert obj.start_with?(str), msg
end
def assert_end_with(obj, str, msg = nil)
msg = message(msg) {
"Expected\n#{obj}\nto end with #{str}"
}
assert_respond_to obj, :end_with?
assert obj.end_with?(str), msg
end
# if obj is longer than 80 characters, show as string, not inspected
def assert_match(matcher, obj, msg = nil)
msg = if obj.length < 80
message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
else
message(msg) { "Expected #{mu_pp matcher} to match:\n#{obj}\n" }
end
assert_respond_to matcher, :"=~"
matcher = Regexp.new Regexp.escape matcher if String === matcher
assert matcher =~ obj, msg
end
end
end
module Minitest
module Assertions
prepend TestPuma::Assertions
end
end