Class: Smartest::ContainExactlyMatcher

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

Instance Method Summary collapse

Methods inherited from Matcher

#and, #or

Constructor Details

#initialize(expected_items, matcher_name:) ⇒ ContainExactlyMatcher

Returns a new instance of ContainExactlyMatcher.



406
407
408
409
410
# File 'lib/smartest/matchers.rb', line 406

def initialize(expected_items, matcher_name:)
  @expected_items = expected_items
  @matcher_name = matcher_name
  reset_result
end

Instance Method Details

#descriptionObject



431
432
433
# File 'lib/smartest/matchers.rb', line 431

def description
  "#{@matcher_name} #{format_expected_items(@expected_items)}"
end

#failure_messageObject



421
422
423
424
425
# File 'lib/smartest/matchers.rb', line 421

def failure_message
  details = failure_details
  message = "expected #{@actual.inspect} to #{@matcher_name} #{format_expected_items(@expected_items)}"
  details.empty? ? message : "#{message}; #{details.join('; ')}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


412
413
414
415
416
417
418
419
# File 'lib/smartest/matchers.rb', line 412

def matches?(actual)
  @actual = actual
  reset_result
  return false unless actual_items?

  match_items
  @missing_items.empty? && @extra_items.empty?
end

#negated_failure_messageObject



427
428
429
# File 'lib/smartest/matchers.rb', line 427

def negated_failure_message
  "expected #{@actual.inspect} not to #{@matcher_name} #{format_expected_items(@expected_items)}"
end