Class: Spec::Matchers::SmartMatch
- Defined in:
- lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected) ⇒ SmartMatch
constructor
A new instance of SmartMatch.
- #matches?(actual) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected) ⇒ SmartMatch
Returns a new instance of SmartMatch.
4 5 6 |
# File 'lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb', line 4 def initialize(expected) @expected = expected end |
Instance Method Details
#failure_message ⇒ Object
24 25 26 |
# File 'lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb', line 24 def "expected #{@actual.inspect} to smart_match #{@expected.inspect}, but it didn't" end |
#matches?(actual) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb', line 8 def matches?(actual) @actual = actual # Satisfy expectation here. Return false or raise an error if it's not met. if @expected =~ /^\/.*\/?$/ || @expected =~ /^".*"$/ regex_or_string = eval(@expected) if Regexp === regex_or_string (@actual =~ regex_or_string) ? true : false else @actual.index(regex_or_string) != nil end else false end end |
#negative_failure_message ⇒ Object
28 29 30 |
# File 'lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb', line 28 def "expected #{@actual.inspect} not to smart_match #{@expected.inspect}, but it did" end |