Class: Spec::Matchers::SmartMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb

Instance Method Summary collapse

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_messageObject



24
25
26
# File 'lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb', line 24

def failure_message
  "expected #{@actual.inspect} to smart_match #{@expected.inspect}, but it didn't"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (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_messageObject



28
29
30
# File 'lib/gems/rspec-1.1.11/stories/resources/matchers/smart_match.rb', line 28

def negative_failure_message
  "expected #{@actual.inspect} not to smart_match #{@expected.inspect}, but it did"
end