Class: Riot::SizeMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::SizeMacro
- 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
Instance Method Summary collapse
-
#devaluate(actual, expected) ⇒ Array
Supports negative/converse assertion testing.
-
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing.
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.
26 27 28 29 |
# File 'lib/riot/assertion_macros/size.rb', line 26 def devaluate(actual, expected) = .size_of(actual).to_not_be(expected).not(actual.size) expected === actual.size ? fail() : pass(.is_size(expected)) end |
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing. This is where magic happens.
19 20 21 22 |
# File 'lib/riot/assertion_macros/size.rb', line 19 def evaluate(actual, expected) = .size_of(actual).to_be(expected).not(actual.size) expected === actual.size ? pass(.is_of_size(expected)) : fail() end |