Class: Riot::NilMacro

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

Overview

Asserts that the result of the test is nil

asserts("test") { nil }.nil
should("test") { nil }.nil

You could test that the result is not nil, but it would make more sense to use the exists macro:

denies("test") { "foo" }.nil
asserts("test") { "foo" }.exists

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) ⇒ Array

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

Parameters:

Returns:



20
21
22
# File 'lib/riot/assertion_macros/nil.rb', line 20

def devaluate(actual)
  actual.nil? ? fail(expected_message.is_nil.not('non-nil')) : pass("is nil")
end

#evaluate(actual) ⇒ Array

Supports positive assertion testing. This is where magic happens.

Parameters:

Returns:



15
16
17
# File 'lib/riot/assertion_macros/nil.rb', line 15

def evaluate(actual)
  actual.nil? ? pass("is nil") : fail(expected_message.nil.not(actual))
end