Class: RSpec::SSE::Matchers::ContainExactlyMatcher

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rspec/sse/matchers.rb

Overview

Base matcher for contain exactly matching (order doesn’t matter)

Instance Method Summary collapse

Methods inherited from BaseMatcher

#failure_message, #failure_message_when_negated, #initialize, #match_arrays, #match_items, #matches?

Constructor Details

This class inherits a constructor from RSpec::SSE::Matchers::BaseMatcher

Instance Method Details

#descriptionObject



373
374
375
# File 'lib/rspec/sse/matchers.rb', line 373

def description
  "contain exactly #{@expected.inspect} in any order"
end

#match_conditionObject

Match if extracted actual values match expected values in any order



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/rspec/sse/matchers.rb', line 353

def match_condition
  return false unless extract_actual.size == @expected.size

  matched_indices = {}
  @expected.each do |expected_item|
    matched = false
    extract_actual.each_with_index do |actual_item, index|
      next if matched_indices[index]
      if match_items(actual_item, expected_item)
        matched_indices[index] = true
        matched = true
        break
      end
    end
    return false unless matched
  end
  true
end