Class: Smartest::ContainExactlyMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(expected_items, matcher_name:) ⇒ ContainExactlyMatcher

Returns a new instance of ContainExactlyMatcher.



251
252
253
254
255
# File 'lib/smartest/matchers.rb', line 251

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

Instance Method Details

#descriptionObject



276
277
278
# File 'lib/smartest/matchers.rb', line 276

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

#failure_messageObject



266
267
268
269
270
# File 'lib/smartest/matchers.rb', line 266

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)


257
258
259
260
261
262
263
264
# File 'lib/smartest/matchers.rb', line 257

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

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

#negated_failure_messageObject



272
273
274
# File 'lib/smartest/matchers.rb', line 272

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