Class: NormalizedHash::Matchers::HashMatchers

Inherits:
Object
  • Object
show all
Defined in:
lib/normalized_hash/matchers.rb

Direct Known Subclasses

ArrayValues, HashKeys, HashValues, SameArrayValues

Instance Method Summary collapse

Constructor Details

#initialize(expectation) ⇒ HashMatchers

Returns a new instance of HashMatchers.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/normalized_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