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 Method Summary collapse

Methods inherited from AssertionMacro

default, #error, expects_exception!, #expects_exception?, #fail, #pass, register

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 = "size of #{actual.inspect} expected to be #{expected} but is #{actual.size}"
  expected === actual.size ? pass("is of size #{expected}") : fail(failure_message)
end