Class: Riot::ExistsMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::ExistsMacro
- Defined in:
- lib/riot/assertion_macros/exists.rb
Overview
Asserts that the result of the test is a non-nil value. This is useful in the case where you don’t want to translate the result of the test into a boolean value
asserts("test") { "foo" }.exists
should("test") { 123 }.exists
asserts("test") { "" }.exists
asserts("test") { nil }.exists # This would fail
You can also test for non-existince (being nil), but if you would better if you used the nil
macro:
denies("test") { nil }.exists # would pass
asserts("test") { nil }.nil # same thing
denies("test") { "foo" }.exists # would fail
Instance Attribute Summary
Attributes inherited from AssertionMacro
Instance Method Summary collapse
-
#devaluate(actual) ⇒ Array
Supports negative/converse assertion testing.
-
#evaluate(actual) ⇒ 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) ⇒ Array
Supports negative/converse assertion testing. This is also where magic happens.
25 26 27 |
# File 'lib/riot/assertion_macros/exists.rb', line 25 def devaluate(actual) actual.nil? ? pass("does exist") : fail("expected a nil value") end |
#evaluate(actual) ⇒ Array
Supports positive assertion testing. This is where magic happens.
20 21 22 |
# File 'lib/riot/assertion_macros/exists.rb', line 20 def evaluate(actual) actual.nil? ? fail("expected a non-nil value") : pass("does exist") end |