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+/)
You can also test that the result does not match your regex:
denies("test") { "hello, world"}.matches(/\d+/)
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 33 |
# File 'lib/riot/assertion_macros/matches.rb', line 26 def devaluate(actual, expected) expected = %r[#{Regexp.escape(expected)}] if expected.kind_of?(String) if actual.to_s =~ expected fail((expected).not_to_match(actual)) else pass(.matches(expected)) end end |
#evaluate(actual, expected) ⇒ Array
Supports positive assertion testing. This is where magic happens.
15 16 17 18 19 20 21 22 |
# File 'lib/riot/assertion_macros/matches.rb', line 15 def evaluate(actual, expected) expected = %r[#{Regexp.escape(expected)}] if expected.kind_of?(String) if actual.to_s =~ expected pass(.matches(expected)) else fail((expected).to_match(actual)) end end |