Class: RSpec::JsonMatchers::Expectations::Mixins::BuiltIn::HashWithContent

Inherits:
Core::SingleValueCallableExpectation show all
Defined in:
lib/rspec/json_matchers/expectations/mixins/built_in.rb

Overview

Takes a Hash Validates value to be Hash and contain expected keys & values Extra keys in value will not be treated as “unexpected” Unless #with_exact_keys is used

Instance Method Summary collapse

Methods inherited from Core::SingleValueCallableExpectation

[]

Methods inherited from Core::CallableExpectation

[]

Methods inherited from RSpec::JsonMatchers::Expectation

build, build_many

Instance Method Details

#expect?(value) ⇒ Boolean

Returns:

  • (Boolean)


207
208
209
210
211
# File 'lib/rspec/json_matchers/expectations/mixins/built_in.rb', line 207

def expect?(value)
  matches_expected_class?(value) &&
    matches_content_expectations?(value) &&
    matches_keys_exactly?(value)
end

#with_exact_keysObject

After calling this method Any extra key in value will be marked as “unexpected”

By default the expectation won’t care about extra keys in value



217
218
219
220
# File 'lib/rspec/json_matchers/expectations/mixins/built_in.rb', line 217

def with_exact_keys
  @require_exact_key_matches = true
  self
end