class ProtoPharm::Matchers::HashArgumentMatcher
Base class for Hash matchers github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
Public Class Methods
from_rspec_matcher(matcher)
click to toggle source
# File lib/proto_pharm/matchers/hash_argument_matcher.rb, line 38 def self.from_rspec_matcher(matcher) new(matcher.instance_variable_get(:@expected)) end
new(expected)
click to toggle source
# File lib/proto_pharm/matchers/hash_argument_matcher.rb, line 26 def initialize(expected) @expected = Hash[ ProtoPharm::Matchers::HashArgumentMatcher.stringify_keys!(expected, deep: true).sort, ] end
stringify_keys!(arg, options = {})
click to toggle source
# File lib/proto_pharm/matchers/hash_argument_matcher.rb, line 8 def self.stringify_keys!(arg, options = {}) case arg when Array arg.map do |elem| options[:deep] ? stringify_keys!(elem, options) : elem end when Hash Hash[ *arg.map do |key, value| k = key.is_a?(Symbol) ? key.to_s : key v = (options[:deep] ? stringify_keys!(value, options) : value) [k, v] end.inject([]) { |r, x| r + x }] else arg end end
Public Instance Methods
==(_actual, &block)
click to toggle source
# File lib/proto_pharm/matchers/hash_argument_matcher.rb, line 32 def ==(_actual, &block) @expected.all?(&block) rescue NoMethodError false end