summaryrefslogtreecommitdiffstats
path: root/test/lib/spec/matchers/match.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/spec/matchers/match.rb')
-rw-r--r--test/lib/spec/matchers/match.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/lib/spec/matchers/match.rb b/test/lib/spec/matchers/match.rb
new file mode 100644
index 000000000..61ab52429
--- /dev/null
+++ b/test/lib/spec/matchers/match.rb
@@ -0,0 +1,41 @@
+module Spec
+ module Matchers
+
+ class Match #:nodoc:
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(actual)
+ @actual = actual
+ return true if actual =~ @expected
+ return false
+ end
+
+ def failure_message
+ return "expected #{@actual.inspect} to match #{@expected.inspect}", @expected, @actual
+ end
+
+ def negative_failure_message
+ return "expected #{@actual.inspect} not to match #{@expected.inspect}", @expected, @actual
+ end
+
+ def description
+ "match #{@expected.inspect}"
+ end
+ end
+
+ # :call-seq:
+ # should match(regexp)
+ # should_not match(regexp)
+ #
+ # Given a Regexp, passes if actual =~ regexp
+ #
+ # == Examples
+ #
+ # email.should match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
+ def match(regexp)
+ Matchers::Match.new(regexp)
+ end
+ end
+end