changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/stories/resources/matchers/smart_match.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1module Spec
2 module Matchers
3 class SmartMatch
4 def initialize(expected)
5 @expected = expected
6 end
7
8 def matches?(actual)
9 @actual = actual
10 # Satisfy expectation here. Return false or raise an error if it's not met.
11
12 if @expected =~ /^\/.*\/?$/ || @expected =~ /^".*"$/
13 regex_or_string = eval(@expected)
14 if Regexp === regex_or_string
15 (@actual =~ regex_or_string) ? true : false
16 else
17 @actual.index(regex_or_string) != nil
18 end
19 else
20 false
21 end
22 end
23
24 def failure_message
25 "expected #{@actual.inspect} to smart_match #{@expected.inspect}, but it didn't"
26 end
27
28 def negative_failure_message
29 "expected #{@actual.inspect} not to smart_match #{@expected.inspect}, but it did"
30 end
31 end
32
33 def smart_match(expected)
34 SmartMatch.new(expected)
35 end
36 end
37end