Class: Smartest::MatchMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(regexp) ⇒ MatchMatcher

Returns a new instance of MatchMatcher.



226
227
228
# File 'lib/smartest/matchers.rb', line 226

def initialize(regexp)
  @regexp = regexp
end

Instance Method Details

#descriptionObject



245
246
247
# File 'lib/smartest/matchers.rb', line 245

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

#failure_messageObject



237
238
239
# File 'lib/smartest/matchers.rb', line 237

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


230
231
232
233
234
235
# File 'lib/smartest/matchers.rb', line 230

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

#negated_failure_messageObject



241
242
243
# File 'lib/smartest/matchers.rb', line 241

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