method
match
1.1.12 -
Show latest stable
- Class:
Spec::Matchers
match(regexp)public
Given a Regexp, passes if actual =~ regexp
Examples
email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
2Notes
Careful when comparing strings
Input String is treated as Regexp:
"*test*".should match "*test*" #=> fail
"*test*".should match ".*test.*" #=> pass
Regexp special characters inside input String can't [be] escaped:
"test".should match "\test\" #=> fail "test".should match /\test\/ #=> pass
Input strings are treated as regexp
Input strings are treated as regexp, but you can escape special regexp characters as usual:
"test".should match "\\test\\" #=> pass "test".should match '\test\' #=> pass "test".should match /\test\/ #=> pass