Class: Riot::IncludesMacro

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

Overview

Asserts the result contains the expected element

asserts("a string") { "world" }.includes('o')
asserts("an array") { [1,2,3] }.includes(2)
asserts("a range") { (1..15) }.includes(10)

You can also assert that the result does not contain an element:

denies("a string") { "world" }.includes('f')
denies("an array") { [1,2,3,4,5] }.includes(0)
denies("a range") { (1..15) }.includes(16)

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 (Object)

    the object that is not expected to be included

Returns:



28
29
30
31
32
33
34
# File 'lib/riot/assertion_macros/includes.rb', line 28

def devaluate(actual, expected)
  if actual.include?(expected)
    fail expected_message(actual).to_not_include(expected)
  else
    pass new_message.includes(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 (Object)

    the object that is expected to be included

Returns:



18
19
20
21
22
23
24
# File 'lib/riot/assertion_macros/includes.rb', line 18

def evaluate(actual, expected)
  if actual.include?(expected)
    pass new_message.includes(expected)
  else
    fail expected_message(actual).to_include(expected)
  end
end