File: expect.rb

package info (click to toggle)
ruby-brass 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 104 kB
  • sloc: ruby: 172; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 631 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
module Kernel

  # TODO: Should `#expect` method be part of standard?

  # Executate a block asserting that a type of error will be raised.
  #
  # Presently this is not part of brass by default, as whether it should
  # be is under debate. So this file must be required separately:
  #
  #   require 'brass/expect'
  #
  def expect(error_class) #:yield:
    begin
      yield
      assert(false, error_class, "#{error_class} expected but none thrown")
    rescue error_class
      assert(true)
    rescue Exception => err
      assert(false, error_class, "#{error_class} expected but #{err.class} was thrown")
    end
  end

end