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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
module CustomAssertions
def assert_connection_error(type, &blk)
assert_http_error(Plum::RemoteConnectionError, type, &blk)
end
def assert_stream_error(type, &blk)
assert_http_error(Plum::RemoteStreamError, type, &blk)
end
def assert_no_error(stream: nil, connection: nil, &blk)
Plum::RemoteConnectionError.reset
Plum::RemoteStreamError.reset
begin
blk.call
rescue Plum::RemoteHTTPError
end
assert_nil(Plum::RemoteStreamError.last, "No stream error expected but raised: #{Plum::RemoteStreamError.last}")
assert_nil(Plum::RemoteConnectionError.last, "No connection error expected but raised: #{Plum::RemoteConnectionError.last}")
end
def assert_frame(frame, **args)
args.each do |name, value|
assert_equal(value, frame.__send__(name))
end
end
private
def assert_http_error(klass, type, &blk)
klass.reset
begin
blk.call
rescue klass
end
last = klass.last
assert(last, "#{klass.name} type: #{type} expected but nothing was raised.")
assert_equal(type, last, "#{klass.name} type: #{type} expected but type: #{last} was raised.")
end
end
Minitest::Test.__send__(:prepend, CustomAssertions)
module LastErrorExtension
def initialize(type, message = nil)
super
self.class.last = type
end
module ClassMethods
attr_accessor :last
def reset
self.last = nil
end
end
def self.prepended(base)
base.extend(ClassMethods)
base.reset
end
end
Plum::RemoteConnectionError.__send__(:prepend, LastErrorExtension)
Plum::RemoteStreamError.__send__(:prepend, LastErrorExtension)
|