Class: Test::Unit::Assertions::AssertExceptionHelper
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/test/unit/assertions.rb |
Class Method Summary
Instance Method Summary
- #expected?(actual_exception, equality = nil) ⇒ Boolean
- #expected_exceptions
- #exception_class?(exception_type) ⇒ Boolean private
- #exception_object?(exception_type) ⇒ Boolean private
- #expected_class?(actual_exception, equality) ⇒ Boolean private
- #expected_module?(actual_exception) ⇒ Boolean private
- #expected_object?(actual_exception) ⇒ Boolean private
- #fallback_exception_object_equal(expected_object, actual_exception) private
- #split_expected_exceptions(expected_exceptions) private
Constructor Details
.new(test_case, expected_exceptions) ⇒ AssertExceptionHelper
# File 'lib/test/unit/assertions.rb', line 2432
def initialize(test_case, expected_exceptions) @test_case = test_case @expected_exceptions = expected_exceptions @expected_classes, @expected_modules, @expected_objects = split_expected_exceptions(expected_exceptions) end
Instance Method Details
#exception_class?(exception_type) ⇒ Boolean
(private)
# File 'lib/test/unit/assertions.rb', line 2498
def exception_class?(exception_type) return true if exception_type <= Exception if Object.const_defined?(:Java) return true if exception_type <= Java::JavaLang::Throwable end false end
#exception_object?(exception_type) ⇒ Boolean
(private)
# File 'lib/test/unit/assertions.rb', line 2488
def exception_object?(exception_type) return true if exception_type.is_a?(Exception) if Object.const_defined?(:Java) return true if exception_type.is_a?(Java::JavaLang::Throwable) end false end
#expected?(actual_exception, equality = nil) ⇒ Boolean
# File 'lib/test/unit/assertions.rb', line 2454
def expected?(actual_exception, equality=nil) equality ||= :instance_of? expected_class?(actual_exception, equality) or expected_module?(actual_exception) or expected_object?(actual_exception) end
#expected_class?(actual_exception, equality) ⇒ Boolean
(private)
# File 'lib/test/unit/assertions.rb', line 2508
def expected_class?(actual_exception, equality) @expected_classes.any? do |expected_class| actual_exception.__send__(equality, expected_class) end end
#expected_exceptions
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 2439
def expected_exceptions exceptions = @expected_exceptions.collect do |exception| if exception.is_a?(Exception) WrappedException.new(exception) else exception end end if exceptions.size == 1 exceptions[0] else exceptions end end
#expected_module?(actual_exception) ⇒ Boolean
(private)
# File 'lib/test/unit/assertions.rb', line 2514
def expected_module?(actual_exception) @expected_modules.any? do |expected_module| actual_exception.is_a?(expected_module) end end
#expected_object?(actual_exception) ⇒ Boolean
(private)
# File 'lib/test/unit/assertions.rb', line 2520
def expected_object?(actual_exception) @expected_objects.any? do |expected_object| expected_object == actual_exception or fallback_exception_object_equal(expected_object, actual_exception) end end
#fallback_exception_object_equal(expected_object, actual_exception) (private)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 2527
def fallback_exception_object_equal(expected_object, actual_exception) owner = Util::MethodOwnerFinder.find(expected_object, :==) if owner == Kernel or owner == Exception expected_object.class == actual_exception.class and expected_object. == actual_exception. else false end end
#split_expected_exceptions(expected_exceptions) (private)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 2462
def split_expected_exceptions(expected_exceptions) exception_modules = [] exception_objects = [] exception_classes = [] expected_exceptions.each do |exception_type| if exception_type.instance_of?(Module) exception_modules << exception_type elsif exception_object?(exception_type) exception_objects << exception_type elsif exception_class?(exception_type) exception_classes << exception_type else = @test_case.__send__(:, nil, "<?> must be " + "a subclass of Exception, " + "an object of Exception subclasses " + "or a Module", exception_type) @test_case.flunk( ) end end [exception_classes, exception_modules, exception_objects] end