]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/stories/resources/matchers/smart_match.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / stories / resources / matchers / smart_match.rb
1 module 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
37 end