Class: Riot::SizeMacro

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

Overview

Asserts that result's size is as expected. Expected size can be specified as a number or a range.

asserts("a string") { 'washington' }.size(9..12)
asserts("an array") { [1, 2, 3] }.size(3)
asserts("a hash") { {:name => 'washington'} }.size(1)

To ensure that the result is not of a specific size:

denies("a string") { 'washington' }.size(4)
denies("an array") { [1, 2, 3] }.size(6..10)
denies("a hash") { {:name => 'washington'} }.size(2)

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

- (Array) devaluate(actual, expected)

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

Parameters:

  • actual (Object)

    the value returned from evaling the Assertion block

  • expected (Number)

    the unexpected size of actual

Returns:



26
27
28
29
# File 'lib/riot/assertion_macros/size.rb', line 26

def devaluate(actual, expected)
  failure_message = expected_message.size_of(actual).to_not_be(expected).not(actual.size)
  expected === actual.size ? fail(failure_message) : pass(new_message.is_size(expected))
end

- (Array) evaluate(actual, expected)

Supports positive assertion testing. This is where magic happens.

Parameters:

  • actual (Object)

    the value returned from evaling the Assertion block

  • expected (Number)

    the expected size of actual

Returns:



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

def evaluate(actual, expected)
  failure_message = expected_message.size_of(actual).to_be(expected).not(actual.size)
  expected === actual.size ? pass(new_message.is_of_size(expected)) : fail(failure_message)
end