File: exceptionhandler.rb

package info (click to toggle)
libcairo-ruby 1.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,476 kB
  • ctags: 5,116
  • sloc: ruby: 9,621; ansic: 6,413; sh: 19; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (5)
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
module Test
  module Unit
    module ExceptionHandler
      @@exception_handlers = []
      class << self
        def exception_handlers
          @@exception_handlers
	end

        def included(base)
          base.extend(ClassMethods)

          observer = Proc.new do |test_case, _, _, value, method_name|
            if value
              @@exception_handlers.unshift(method_name)
            else
              @@exception_handlers -= [method_name]
            end
          end
          base.register_attribute_observer(:exception_handler, &observer)
        end
      end

      module ClassMethods
        def exception_handlers
          ExceptionHandler.exception_handlers
        end

        def exception_handler(*method_names)
          attribute(:exception_handler, true, *method_names)
        end

        def unregister_exception_handler(*method_names)
          attribute(:exception_handler, false, *method_names)
        end
      end
    end
  end
end