Module: RSpec::JsonApi::CompareHash

Extended by:
CompareHash
Included in:
CompareHash
Defined in:
lib/rspec/json_api/compare_hash.rb

Constant Summary collapse

SUPPORTED_OPTIONS =
%i[allow_blank type value min max inclusion regex lambda].freeze

Instance Method Summary collapse

Instance Method Details

#compare(actual, expected) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rspec/json_api/compare_hash.rb', line 10

def compare(actual, expected)
  return false if actual.blank? && expected.present?

  key_paths = actual.deep_key_paths

  key_paths.all? do |key_path|
    actual_value = actual.dig(*key_path)
    expected_value = expected.dig(*key_path)

    compare_hash_values(actual_value, expected_value)
  end
end