Class: Smartest::MatchMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/smartest/matchers.rb

Instance Method Summary collapse

Methods inherited from Matcher

#and, #or

Constructor Details

#initialize(regexp) ⇒ MatchMatcher

Returns a new instance of MatchMatcher.



381
382
383
# File 'lib/smartest/matchers.rb', line 381

def initialize(regexp)
  @regexp = regexp
end

Instance Method Details

#descriptionObject



400
401
402
# File 'lib/smartest/matchers.rb', line 400

def description
  "match #{@regexp.inspect}"
end

#failure_messageObject



392
393
394
# File 'lib/smartest/matchers.rb', line 392

def failure_message
  "expected #{@actual.inspect} to match #{@regexp.inspect}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


385
386
387
388
389
390
# File 'lib/smartest/matchers.rb', line 385

def matches?(actual)
  @actual = actual
  @regexp.match?(actual)
rescue NoMethodError, TypeError
  false
end

#negated_failure_messageObject



396
397
398
# File 'lib/smartest/matchers.rb', line 396

def negated_failure_message
  "expected #{@actual.inspect} not to match #{@regexp.inspect}"
end