Class: RSpec::JsonExpectations::JsonTraverser

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/json_expectations/json_traverser.rb

Overview

This class allows to traverse a json actual value along with json expected value for inclusion and check if they match. Errors are accumulated in errors hash for each json atom paths.

Constant Summary collapse

HANDLED_BY_SIMPLE_VALUE_HANDLER =
[String, Numeric, FalseClass, TrueClass, NilClass]
RSPECMATCHERS =
[RSpec::Matchers::BuiltIn::BaseMatcher, RSpec::Matchers::AliasedMatcher]
SUPPORTED_VALUES =
[Hash, Regexp, Array, Matchers::UnorderedArrayMatcher] +
HANDLED_BY_SIMPLE_VALUE_HANDLER + RSPECMATCHERS

Class Method Summary collapse

Class Method Details

.traverse(errors, expected, actual, negate = false, prefix = [], options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rspec/json_expectations/json_traverser.rb', line 17

def traverse(errors, expected, actual, negate=false, prefix=[], options={})
  [
    handle_hash(errors, expected, actual, negate, prefix),
    handle_array(errors, expected, actual, negate, prefix),
    handle_unordered(errors, expected, actual, negate, prefix, options),
    handle_value(errors, expected, actual, negate, prefix),
    handle_regex(errors, expected, actual, negate, prefix),
    handle_rspec_matcher(errors, expected, actual, negate, prefix),
    handle_unsupported(expected)
  ].any?
end