Class: Riot::IncludesMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::IncludesMacro
- 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
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.
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 (actual).to_not_include(expected) else pass .includes(expected) end end |
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing. This is where magic happens.
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 .includes(expected) else fail (actual).to_include(expected) end end |