aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/assertions.rb
blob: 7c4b094043efb5f23a991685da9c6341d4d5aa89 (plain)
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
module CustomAssertions
  def assert_http_error(klass, type, &blk)
    begin
      blk.call
    rescue klass => e
      assert_equal(type, e.http2_error_type)
    else
      flunk "#{klass.name} type: #{type} expected but nothing was raised."
    end
  end

  def assert_connection_error(type, &blk)
    assert_http_error(Plum::ConnectionError, type, &blk)
  end

  def assert_stream_error(type, &blk)
    assert_http_error(Plum::StreamError, type, &blk)
  end

  def refute_raises(&blk)
    begin
      blk.call
    rescue
      a = $!
    else
      a = nil
    end
    assert(!a, "No exceptions expected but raised: #{a}:\n#{a && a.backtrace.join("\n")}")
  end
end

class Minitest::Test
  include CustomAssertions
end