Class: Riot::EquivalentToMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::EquivalentToMacro
- Defined in:
- lib/riot/assertion_macros/equivalent_to.rb
Overview
Asserts that the result of the test is equivalent to the expected value. Using the === operator.
asserts("test") { "foo" }.equivalent_to(String)
should("test") { "foo" }.equivalent_to("foo")
asserts("test") { "foo" }.equivalent_to { "foo" }
You can also assert that the expected value is not equivalent to something else:
denies("test") { "foo" }.equivalent_to(Boolean)
denies("test") { "foo" }.equivalent_to("bar")
Underneath the hood, this assertion macro uses:
expected === actual
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.
31 32 33 34 35 36 37 |
# File 'lib/riot/assertion_macros/equivalent_to.rb', line 31 def devaluate(actual, expected) if expected === actual fail (actual).not_to_be_equivalent_to(expected) else pass .is_equivalent_to(expected) end end |
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing. This is where magic happens.
21 22 23 24 25 26 27 |
# File 'lib/riot/assertion_macros/equivalent_to.rb', line 21 def evaluate(actual, expected) if expected === actual pass .is_equivalent_to(expected) else fail (actual).to_be_equivalent_to(expected) end end |