lib/ass_tests/minitest/assertions.rb in ass_tests-1.0.0.alpha vs lib/ass_tests/minitest/assertions.rb in ass_tests-1.2.0.alpha

- old
+ new

@@ -11,13 +11,18 @@ end end module AssTests module Assertions - # TODO: It works bad + UNKNOWN_XML_TYPE = 'UNKNOWN_XML_TYPE' + + GOOD_OLE_CONNECTORS = [ + AssLauncher::Enterprise::Ole::IbConnection, + AssLauncher::Enterprise::Ole::ThickApplication + ] def _assert_xml_type(exp, obj, mess = nil) - act = ole_connector.xmlTypeOf(obj).typeName + act = xml_type_get(obj) mess = message(mess) do "Expected #{exp} xml type but #{act} given" end assert exp == act, mess end @@ -42,18 +47,45 @@ def to_comparable(obj) return obj unless obj.is_a? WIN32OLE return obj.__real_obj__ if obj.__ruby__? # TODO: make comparsation ruby object from internal Ass string + + return to_comparable_srv_context(obj) if\ + GOOD_OLE_CONNECTORS.include? ole_connector.class + to_comparable_client_context(obj) + end + private :to_comparable + + def to_comparable_client_context(obj) + fail 'You should define own method #to_comparable_client_context'\ + ' and returns #new_comparable Hash' + end + private :to_comparable_client_context + + def to_comparable_srv_context(obj) + new_comparable ole_connector.sTring(obj), + xml_type_get(obj), + ole_connector.ValueToStringInternal(obj) + end + private :to_comparable_srv_context + + def new_comparable(as_string, xml_type, as_string_internal) r = {} - r[:as_string] = ole_connector.sTring obj - r[:xml_type] = ole_connector.xmlTypeOf(obj).typeName - r[:as_string_internal] = ole_connector.ValueToStringInternal obj + r[:as_string] = as_string + r[:xml_type] = xml_type + r[:as_string_internal] = as_string_internal r end - private :to_comparable + private :new_comparable + def xml_type_get(obj) + return UNKNOWN_XML_TYPE if ole_connector.xmlTypeOf(obj).nil? + ole_connector.xmlTypeOf(obj).typeName + end + private :xml_type_get + def not_comparable?(exp, act) is_ruby?(exp) ^ is_ruby?(act) end private :not_comparable? @@ -62,12 +94,18 @@ end private :is_ruby? def fail_not_comparable(exp, act) fail ArgumentError, - "Not comparable types `#{exp.__real_object__.class}'"\ - " and `#{act.__real_object__.class}'" + "Not comparable types `#{not_comparable_class exp}'"\ + " and `#{not_comparable_class act}'" end private :fail_not_comparable + + def not_comparable_class(obj) + return obj.__real_obj__.class if obj.respond_to? :__real_obj__ + obj.class + end + private :not_comparable_class end end