Class: Deep::Matchers::HashMatchers

Inherits:
Object
  • Object
show all
Defined in:
parser/spec/lib/deep/hash_matchers.rb

Direct Known Subclasses

ArrayValues, HashKeys, HashValues, SameArrayValues

Instance Method Summary (collapse)

Constructor Details

- (HashMatchers) initialize(expectation)

A new instance of HashMatchers



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'parser/spec/lib/deep/hash_matchers.rb', line 9

def initialize(expectation)
  # Convert to array for simpler checks
  @expectation = [expectation].flatten
  
  # All expectionations should be Class, no other classes
  unless @expectation.map(&:class).uniq == [Class]
    raise ArgumentError,
    "#{@expectation.inspect}: Expectation should be Class or Array[of Classes], got #{@expectation.class}"
  end

  # Expand expectation with all numeric classes if at least one
  # numeric present.
  (@expectation += NUMBERS).uniq! unless (@expectation & NUMBERS).empty?

end