Method: Test::Unit::Assertions#assert_type_has_instance_methods
- Defined in:
- lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb
#assert_type_has_instance_methods(type, message_spec, failure_message = nil) ⇒ Object
Fails unless the given type responds to all of the messages given by message_spec
Signature
-
Parameters:
-
type(::Class) The type -
message_spec(::Symbol, ::Array, ::Hash) A specification of message(s) received by the instances oftype. If a ::Symbol, then instances must respond to this single message. If an ::Array (all elements of which must be ::Symbol), then instances must respond to all messages. If a ::Hash, then instances must respond to all messages represented by the keys; the values are available for specifying a custom failure message (or value isnilfor stock message)
-
-
failure_message(::String) If specified, is used when instances oftypedo not respond to a message and no custom failure message is provided for it
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb', line 18 def assert_type_has_instance_methods(type, , = nil) warn "type parameter - '#{type} (#{type.class})' - should be a Class" unless type.is_a?(::Class) case when ::Hash warn "every key in a Hash message_spec should be of type Symbol" unless .keys.all? { |k| ::Symbol === k } when ::Array warn "every key in an Array message_spec should be of type Symbol" unless .all? { |k| ::Symbol === k } = Hash[.map { |s| [ s, nil ] }] when ::Symbol [] = nil else msg = "message_spec - '#{} (#{.class})' - should be a Symbol, an Array of Symbols, or a Hash of Symbol => message" warn msg return assert false, msg end ims = type.instance_methods .each do |sym, | unless ims.include? sym ||= ||= "type #{type} does not contain the instance method #{sym}" return assert false, end end assert true end |