Class: Suhyo::HashMatchers::IncludeHash

Inherits:
Object
  • Object
show all
Defined in:
lib/suhyo/hash_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ IncludeHash

Returns a new instance of IncludeHash.



3
4
5
# File 'lib/suhyo/hash_matchers.rb', line 3

def initialize(hash)
	@hash = hash
end

Instance Method Details

#failure_messageObject



15
16
17
# File 'lib/suhyo/hash_matchers.rb', line 15

def failure_message
	"Expected hash to include #{@hash.inspect} but got #{@target.inspect}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'lib/suhyo/hash_matchers.rb', line 7

def matches?(target)
	@target = target
	@hash.each do |key, value|
		return false unless target[key] == value
	end
	true
end

#negative_failure_messageObject



19
20
21
# File 'lib/suhyo/hash_matchers.rb', line 19

def negative_failure_message
	"Expected hash not to include #{@hash.inspect} but got #{@target.inspect}"
end