From eaeea29e38e873855d7ed115501c8abe16252d85 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 15 Jul 2018 12:32:02 +0300 Subject: [PATCH] helper erro handling --- lib/parfait/space.rb | 4 +++- test/parfait/test_space.rb | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index b3410c61..441d8589 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -115,7 +115,9 @@ module Parfait # get the current instance_typ of the class with the given name def get_type_by_class_name(name) - get_class_by_name(name).instance_type + clazz = get_class_by_name(name) + return nil unless clazz + clazz.instance_type end # get a class by name (symbol) diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 55e7ebb0..4583ab2c 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -28,6 +28,9 @@ module Parfait def test_get_type_by_class_name assert_equal Parfait::Type , Parfait.object_space.get_type_by_class_name(:Space).class end + def test_get_type_by_class_name_nil + assert_nil Parfait.object_space.get_type_by_class_name(:Spac) + end def test_get_integer_instance int = @space.get_integer assert_equal Integer , int.class