Class: Riot::KindOfMacro

Inherits:
AssertionMacro show all
Defined in:
lib/riot/assertion_macros/kind_of.rb

Overview

Asserts that the result of the test is an object that is a kind of the expected type

asserts("test") { "foo" }.kind_of(String)
should("test") { "foo" }.kind_of(String)

You can also test the result is not a kind of a thing:

denies("test") { "foo" }.kind_of(Boolean)

Instance Attribute Summary

Attributes inherited from AssertionMacro

#file, #line

Instance Method Summary collapse

Methods inherited from AssertionMacro

#error, #expected_message, expects_exception!, #expects_exception?, #fail, #new_message, #pass, register, #should_have_message

Instance Method Details

#devaluate(actual, expected) ⇒ Array

Supports negative/converse assertion testing. This is also where magic happens.

Parameters:

  • actual (Object)

    the value returned from evaling the Assertion block

  • expected (Class)

    the unexpected class of actual

Returns:



25
26
27
28
29
30
31
# File 'lib/riot/assertion_macros/kind_of.rb', line 25

def devaluate(actual, expected)
  if actual.kind_of?(expected)
    fail expected_message.not_kind_of(expected).not(actual.class)
  else
    pass new_message.is_a_kind_of(expected)
  end
end

#evaluate(actual, expected) ⇒ Array

Supports positive assertion testing. This is where magic happens.

Parameters:

  • actual (Object)

    the value returned from evaling the Assertion block

  • expected (Class)

    the expected class of actual

Returns:



15
16
17
18
19
20
21
# File 'lib/riot/assertion_macros/kind_of.rb', line 15

def evaluate(actual, expected)
  if actual.kind_of?(expected)
    pass new_message.is_a_kind_of(expected)
  else
    fail expected_message.kind_of(expected).not(actual.class)
  end
end