Module: Test::Unit::Assertions
- Defined in:
- lib/xqsr3/extensions/test/unit/assert_eql.rb,
lib/xqsr3/extensions/test/unit/assert_not.rb,
lib/xqsr3/extensions/test/unit/assert_true.rb,
lib/xqsr3/extensions/test/unit/assert_false.rb,
lib/xqsr3/extensions/test/unit/assert_not_eql.rb,
lib/xqsr3/extensions/test/unit/assert_subclass_of.rb,
lib/xqsr3/extensions/test/unit/assert_superclass_of.rb,
lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb,
lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb
Instance Method Summary collapse
- #assert_eql(expected, actual, failure_message = '') ⇒ Object
- #assert_false(expression, failure_message = '') ⇒ Object
- #assert_not(test, failure_message = '') ⇒ Object
- #assert_not_eql(expected, actual, failure_message = '') ⇒ Object
- #assert_raise_with_message(type_spec, message_spec, failure_message = nil) ⇒ Object
- #assert_subclass_of(parent_class, tested_class, failure_message = nil) ⇒ Object
- #assert_superclass_of(child_class, tested_class, failure_message = nil) ⇒ Object
- #assert_true(expression, failure_message = '') ⇒ Object
-
#assert_type_has_instance_methods(type, message_spec, failure_message = nil) ⇒ Object
Fails unless the given
type
responds to all of the messages given bymessage_spec
.
Instance Method Details
#assert_eql(expected, actual, failure_message = '') ⇒ Object
9 10 11 12 |
# File 'lib/xqsr3/extensions/test/unit/assert_eql.rb', line 9 def assert_eql(expected, actual, = '') assert expected.eql?(actual), end |
#assert_false(expression, failure_message = '') ⇒ Object
9 10 11 12 |
# File 'lib/xqsr3/extensions/test/unit/assert_false.rb', line 9 def assert_false(expression, = '') assert ::FalseClass === (expression), end |
#assert_not(test, failure_message = '') ⇒ Object
9 10 11 12 |
# File 'lib/xqsr3/extensions/test/unit/assert_not.rb', line 9 def assert_not(test, = '') assert !(test), end |
#assert_not_eql(expected, actual, failure_message = '') ⇒ Object
9 10 11 12 |
# File 'lib/xqsr3/extensions/test/unit/assert_not_eql.rb', line 9 def assert_not_eql(expected, actual, = '') assert !(expected.eql?(actual)), end |
#assert_raise_with_message(type_spec, message_spec, failure_message = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb', line 9 def (type_spec, , = nil) unless block_given? msg = "WARNING: no block_given to assert_raise_with_message() called from: #{caller[0]}" warn "\n#{msg}" assert false, msg end case type_spec when ::Array, nil ; else type_spec = [ type_spec ] end case when ::Array, nil ; else = [ ] end begin yield assert false, "expected did not throw an exception" rescue Exception => x if type_spec assert false, "exception not of any of required types (#{type_spec.join(', ')}); #{x.class} given" unless type_spec.any? { |c| x.is_a? c} end if assert false, "exception message not of any of required messages; '#{x.}' given" unless .any? do |m| case m when ::Regexp x. =~ m when ::String x. == m else warn "\nunsupported message_spec entry '#{m}' (#{m.class})" end end end assert true end end |
#assert_subclass_of(parent_class, tested_class, failure_message = nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/xqsr3/extensions/test/unit/assert_subclass_of.rb', line 9 def assert_subclass_of(parent_class, tested_class, = nil) ||= "#{tested_class} is not a subclass of #{parent_class}" assert (tested_class < parent_class), end |
#assert_superclass_of(child_class, tested_class, failure_message = nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/xqsr3/extensions/test/unit/assert_superclass_of.rb', line 9 def assert_superclass_of(child_class, tested_class, = nil) ||= "#{tested_class} is not a superclass of #{child_class}" assert (child_class < tested_class), end |
#assert_true(expression, failure_message = '') ⇒ Object
9 10 11 12 |
# File 'lib/xqsr3/extensions/test/unit/assert_true.rb', line 9 def assert_true(expression, = '') assert ::TrueClass === (expression), end |
#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 of
type
. 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 isnil
for stock message)
failure_message
- ::String
-
If specified, is used when
instances of +type+ do not respond to a message and no custom failure message is provided for it
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 58 59 60 61 62 63 64 65 66 |
# File 'lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb', line 27 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, msg| unless ims.include? sym msg ||= msg ||= "type #{type} does not contain the instance method #{sym}" return assert false, msg end end assert true end |