Last active
September 23, 2021 23:15
-
-
Save mltsy/21fd5e15ae12a004c8b13d6ec4534458 to your computer and use it in GitHub Desktop.
Revisions
-
Joe Marty revised this gist
Jan 16, 2017 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,5 @@ RSpec::Matchers.define :deep_include do |expected| match { |actual| deep_include? actual, expected } def deep_include?(actual, expected, path = []) return true if actual == expected @@ -25,6 +23,7 @@ def deep_include?(actual, expected, path = []) elsif actual.is_a? Hash return false unless expected.is_a? Hash expected.all? do |key, expected_value| return false unless actual.has_key? key deep_include? actual[key], expected_value, path + [key] end else -
Joe Marty revised this gist
Dec 30, 2016 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,7 @@ def deep_include?(actual, expected, path = []) deep_include? actual_item, expected_item, path + [index] end unless match_found @failing_array = actual @failing_array_path = path + [index] @failing_expected_array_item = expected_item return false @@ -34,11 +35,13 @@ def deep_include?(actual, expected, path = []) failure_message do |actual| if @failing_array_path path = @failing_array_path.map{ |p| "[#{p.inspect}]" }.join path = "root" if path.blank? message = "Actual array did not include value at #{path}: \n" + " expected #{@failing_expected_array_item.inspect}\n" + " but matching value not found in array: #{@failing_array}\n" else path = @failing_path.map{ |p| "[#{p.inspect}]" }.join path = "root" if path.blank? message = "Actual hash did not include expected value at #{path}: \n" + " expected #{@failing_expected.inspect}\n" + " got #{@failing_actual.inspect}\n" -
Joe Marty created this gist
Dec 30, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ RSpec::Matchers.define :deep_include do |expected| match do |actual| deep_include? actual, expected end def deep_include?(actual, expected, path = []) return true if actual == expected @failing_path = path @failing_expected = expected @failing_actual = actual if actual.is_a? Array return false unless expected.is_a? Array expected.each_with_index do |expected_item, index| match_found = actual.any? do |actual_item| deep_include? actual_item, expected_item, path + [index] end unless match_found @failing_array_path = path + [index] @failing_expected_array_item = expected_item return false end end elsif actual.is_a? Hash return false unless expected.is_a? Hash expected.all? do |key, expected_value| deep_include? actual[key], expected_value, path + [key] end else false end end failure_message do |actual| if @failing_array_path path = @failing_array_path.map{ |p| "[#{p.inspect}]" }.join message = "Actual array did not include value at #{path}: \n" + " expected #{@failing_expected_array_item.inspect}\n" + " but matching value not found in array\n" else path = @failing_path.map{ |p| "[#{p.inspect}]" }.join message = "Actual hash did not include expected value at #{path}: \n" + " expected #{@failing_expected.inspect}\n" + " got #{@failing_actual.inspect}\n" end message end end