Class: Riot::MatchesMacro
- Inherits:
-
AssertionMacro
- Object
- AssertionMacro
- Riot::MatchesMacro
- Defined in:
- lib/riot/assertion_macros/matches.rb
Overview
Asserts that the result of the test equals matches against the proved expression
asserts("test") { "12345" }.matches(/\d+/)
should("test") { "12345" }.matches(/\d+/)
Instance Attribute Summary
Attributes inherited from AssertionMacro
Instance Method Summary collapse
Methods inherited from AssertionMacro
default, #error, #expected_message, expects_exception!, #expects_exception?, #fail, #new_message, #pass, register, #should_have_message
Instance Method Details
#evaluate(actual, expected) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/riot/assertion_macros/matches.rb', line 8 def evaluate(actual, expected) expected = %r[#{Regexp.escape(expected)}] if expected.kind_of?(String) if actual =~ expected pass(.matches(expected)) else fail((expected).to_match(actual)) end end |