File: test_utils.rb

package info (click to toggle)
dnsruby 1.61.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,520 kB
  • sloc: ruby: 17,811; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download | duplicates (3)
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
require_relative 'spec_helper'

# Use this in tests in the tests directory with:
# require_relative 'test_utils'
# include TestUtils

module Dnsruby
  module TestUtils

    module_function

    # Asserts that all exceptions whose type are the specified exception class
    # or one of its subclasses are *not* raised.
    #
    # If any other kind of exception is raised, the test throws an exception
    # (rather than failing).
    #
    # The test passes if and only if no exceptions are raised.
    def assert_not_raised(exception_class, failure_message = nil)
      begin
        yield
      rescue => e
        if e.is_a?(exception_class)
          flunk(failure_message || "An exception was not expected but was raised: #{e}")
        else
          raise e
        end
      end
    end

=begin
  # This should result in a test failure:
  def test_target_exception
    assert_not_raised(ArgumentError, 'ArgumentError') { raise ArgumentError.new }
  end

  # This should result in a test error:
  def test_other_exception
    assert_not_raised(ArgumentError, 'RuntimeError') { raise RuntimeError.new }
  end

  # This should result in a passed test:
  def test_no_exception
    assert_not_raised(ArgumentError, 'No Error') { }
  end
=end
  end
end