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)

Instance Attribute Summary

Attributes inherited from AssertionMacro

#file, #line

Instance Method Summary collapse

Methods inherited from AssertionMacro

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

Instance Method Details

#evaluate(actual, expected) ⇒ Object



10
11
12
13
# File 'lib/riot/assertion_macros/size.rb', line 10

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