module Minitest::Hooks::ClassMethods
Constants
- NEW
Object used to get an empty new instance, as new by default will return a dup of the singleton instance.
Public Instance Methods
after(type=nil, &block)
click to toggle source
If type is :all, set the after_all hook instead of the after hook.
Calls superclass method
# File lib/minitest/hooks/test.rb 123 def after(type=nil, &block) 124 if type == :all 125 define_method(:after_all) do 126 instance_exec(&block) 127 super() 128 end 129 nil 130 else 131 super 132 end 133 end
around(type=nil, &block)
click to toggle source
If type is :all, set the around_all hook, otherwise set the around hook.
# File lib/minitest/hooks/test.rb 104 def around(type=nil, &block) 105 meth = type == :all ? :around_all : :around 106 define_method(meth, &block) 107 end
before(type=nil, &block)
click to toggle source
If type is :all, set the before_all hook instead of the before hook.
Calls superclass method
# File lib/minitest/hooks/test.rb 110 def before(type=nil, &block) 111 if type == :all 112 define_method(:before_all) do 113 super() 114 instance_exec(&block) 115 end 116 nil 117 else 118 super 119 end 120 end
new(name)
click to toggle source
Unless name is NEW
, return a dup singleton instance.
Calls superclass method
# File lib/minitest/hooks/test.rb 50 def new(name) 51 if name.equal?(NEW) 52 return super('around_all') 53 end 54 55 instance = @instance.dup 56 instance.name = name 57 instance.failures = [] 58 instance 59 end
with_info_handler(reporter, &block)
click to toggle source
When running the specs in the class, first create a singleton instance, the singleton is used to implement around_all/before_all/after_all hooks, and each spec will run as a dup of the singleton instance.
Calls superclass method
# File lib/minitest/hooks/test.rb 64 def with_info_handler(reporter, &block) 65 @instance = new(NEW) 66 @instance.time = 0 67 @instance.name = "around_all" 68 69 begin 70 @instance.around_all do 71 begin 72 @instance.capture_exceptions do 73 @instance.name = "before_all" 74 @instance.before_all 75 end 76 77 if @instance.failure 78 failed = true 79 _record_minitest_hooks_error(reporter, @instance) 80 else 81 super(reporter, &block) 82 end 83 ensure 84 @instance.capture_exceptions do 85 @instance.name = "after_all" unless failed 86 @instance.after_all 87 end 88 if @instance.failure && !failed 89 failed = true 90 _record_minitest_hooks_error(reporter, @instance) 91 end 92 @instance.name = "around_all" unless failed 93 end 94 end 95 rescue => e 96 @instance.capture_exceptions do 97 raise e 98 end 99 _record_minitest_hooks_error(reporter, @instance) 100 end 101 end
Private Instance Methods
_record_minitest_hooks_error(reporter, instance)
click to toggle source
# File lib/minitest/hooks/test.rb 137 def _record_minitest_hooks_error(reporter, instance) 138 # In MiniTest 5.11+, use Minitest::Result for wrapping the object to send 139 # to the reporter. 140 if(defined?(Minitest::Result)) 141 result = Minitest::Result.from(instance) 142 else 143 result = instance 144 end 145 reporter.record result 146 end