Class: Riot::RespondToMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::RespondToMacro
- Defined in:
- lib/riot/assertion_macros/respond_to.rb
Overview
Asserts that the result of the test is an object that responds to the given method
asserts("test") { "foo" }.respond_to(:to_s)
should("test") { "foo" }.respond_to(:to_s)
If you want to test that the result does not respond to something:
denies("test") { "foo" }.responds_to(:harassment)
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 30 31 32 |
# File 'lib/riot/assertion_macros/respond_to.rb', line 26 def devaluate(actual, expected) if actual.respond_to?(expected) fail(.method(expected).is_defined) else pass .responds_to(expected) end end |
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing. This is where magic happens.
16 17 18 19 20 21 22 |
# File 'lib/riot/assertion_macros/respond_to.rb', line 16 def evaluate(actual, expected) if actual.respond_to?(expected) pass(.responds_to(expected)) else fail(.method(expected).is_not_defined) end end |