Class: ProtoPharm::Matchers::HashArgumentMatcher
- Inherits:
-
Object
- Object
- ProtoPharm::Matchers::HashArgumentMatcher
- Defined in:
- lib/proto_pharm/matchers/hash_argument_matcher.rb
Overview
Base class for Hash matchers github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #==(_actual, &block) ⇒ Object
-
#initialize(expected) ⇒ HashArgumentMatcher
constructor
A new instance of HashArgumentMatcher.
Constructor Details
#initialize(expected) ⇒ HashArgumentMatcher
Returns a new instance of HashArgumentMatcher.
26 27 28 29 30 |
# 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 |
Class Method Details
.from_rspec_matcher(matcher) ⇒ Object
38 39 40 |
# File 'lib/proto_pharm/matchers/hash_argument_matcher.rb', line 38 def self.from_rspec_matcher(matcher) new(matcher.instance_variable_get(:@expected)) end |
.stringify_keys!(arg, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/proto_pharm/matchers/hash_argument_matcher.rb', line 8 def self.stringify_keys!(arg, = {}) case arg when Array arg.map do |elem| [:deep] ? stringify_keys!(elem, ) : elem end when Hash Hash[ *arg.map do |key, value| k = key.is_a?(Symbol) ? key.to_s : key v = ([:deep] ? stringify_keys!(value, ) : value) [k, v] end.inject([]) { |r, x| r + x }] else arg end end |
Instance Method Details
#==(_actual, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/proto_pharm/matchers/hash_argument_matcher.rb', line 32 def ==(_actual, &block) @expected.all?(&block) rescue NoMethodError false end |