Sha256: 41ede589f1d2c034a969f093d7f52ab32456d4c4c9514206e89fc6df61923eda

Contents?: true

Size: 1.48 KB

Versions: 2010

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module RSpec
  module Support
    # Provides a means to fuzzy-match between two arbitrary objects.
    # Understands array/hash nesting. Uses `===` or `==` to
    # perform the matching.
    module FuzzyMatcher
      # @api private
      def self.values_match?(expected, actual)
        if Hash === actual
          return hashes_match?(expected, actual) if Hash === expected
        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 on 1.9+, raise
          # ArgumentError for `expected === actual`.
          false
        end
      end

      # @private
      def self.arrays_match?(expected_list, actual_list)
        return false if expected_list.size != actual_list.size

        expected_list.zip(actual_list).all? do |expected, actual|
          values_match?(expected, actual)
        end
      end

      # @private
      def self.hashes_match?(expected_hash, actual_hash)
        return false if expected_hash.size != actual_hash.size

        expected_hash.all? do |expected_key, expected_value|
          actual_value = actual_hash.fetch(expected_key) { return false }
          values_match?(expected_value, actual_value)
        end
      end

      private_class_method :arrays_match?, :hashes_match?
    end
  end
end

Version data entries

2,010 entries across 2,010 versions & 15 rubygems

Version Path
cybrid_api_organization_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_bank_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_organization_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_id_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rspec-support-3.13.1/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_bank_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_id_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_organization_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
ory-client-1.15.17 vendor/bundle/ruby/3.1.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_bank_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_organization_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_id_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_organization_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_bank_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_id_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_organization_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_bank_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_id_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_bank_ruby-0.123.111 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb
cybrid_api_organization_ruby-0.123.111 vendor/bundle/ruby/3.3.0/gems/rspec-support-3.13.2/lib/rspec/support/fuzzy_matcher.rb