2008-06-18 02:57:57 -04:00
|
|
|
module Spec
|
|
|
|
|
module Matchers
|
|
|
|
|
|
|
|
|
|
class Match #:nodoc:
|
2008-11-29 12:00:06 -05:00
|
|
|
def initialize(regexp)
|
|
|
|
|
@regexp = regexp
|
2008-06-18 02:57:57 -04:00
|
|
|
end
|
|
|
|
|
|
2008-11-29 12:00:06 -05:00
|
|
|
def matches?(given)
|
|
|
|
|
@given = given
|
|
|
|
|
return true if given =~ @regexp
|
2008-06-18 02:57:57 -04:00
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def failure_message
|
2008-11-29 12:00:06 -05:00
|
|
|
return "expected #{@given.inspect} to match #{@regexp.inspect}", @regexp, @given
|
2008-06-18 02:57:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def negative_failure_message
|
2008-11-29 12:00:06 -05:00
|
|
|
return "expected #{@given.inspect} not to match #{@regexp.inspect}", @regexp, @given
|
2008-06-18 02:57:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def description
|
2008-11-29 12:00:06 -05:00
|
|
|
"match #{@regexp.inspect}"
|
2008-06-18 02:57:57 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# :call-seq:
|
|
|
|
|
# should match(regexp)
|
|
|
|
|
# should_not match(regexp)
|
|
|
|
|
#
|
2008-11-29 12:00:06 -05:00
|
|
|
# Given a Regexp, passes if given =~ regexp
|
2008-06-18 02:57:57 -04:00
|
|
|
#
|
|
|
|
|
# == Examples
|
|
|
|
|
#
|
|
|
|
|
# email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
|
|
|
|
|
def match(regexp)
|
|
|
|
|
Matchers::Match.new(regexp)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|