module RSpec::Support::FuzzyMatcher

Provides a means to fuzzy-match between two arbitrary objects. Understands array/hash nesting. Uses ‘===` or `==` to perform the matching.

Public Class Methods

@api private

# File rspec-support/lib/rspec/support/fuzzy_matcher.rb, line 10
def self.values_match?(expected, actual)
  if Hash === actual
    return hashes_match?(expected, actual) if Hash === expected
  elsif Range === expected
    # Check that actual is an equivalent Range, rather than included/covered.
    return expected == actual
  elsif Array === expected && Enumerable === actual && !(Struct === actual)
    return arrays_match?(expected, actual.to_a)
  end

  return true if expected == actual

  begin
    expected === actual
  rescue ArgumentError
    # Some objects, like 0-arg lambdas, raise ArgumentError when compared with ===.
    false
  end
end