Top Level Namespace

Defined Under Namespace

Modules: BelphaniorServantHelper, RoleBuilderUtils, ServantConfigHelper, Sinatra Classes: ServantConfigDb, ServantConfigException, TestRoleBuilder, TestServantConfig, TestServantConfigDb

Instance Method Summary collapse

Instance Method Details

#assert_equivalent_json_objects(reference, tested) ⇒ Object

Test helper function Validates that two JSON-style objects are equivalent Equivalence is defined as follows:

Array type: each element equivalent
Dict type: For each key |k| in reference, key in value
 exists and value for the key is equivalent.
 NOTE: This means that the input can contain
 additional data, and this is acceptable.
All others: Simple ruby equivalence.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/belphanior/servant/test/tc_role_builder.rb', line 18

def assert_equivalent_json_objects(reference, tested)
  assert_equal(reference.class(), tested.class())
  if reference.class() == [].class()
    assert_equal(reference.length, tested.length)
    for i in 0..reference.length
      assert_equivalent_json_objects(
        reference[i], tested[i])
    end
  elsif reference.class() == {}.class()
    reference.each do |key, value|
      assert_equal(true, tested.has_key?(key))
      assert_equivalent_json_objects(value, tested[key])
    end
  else
    # String or number (or other type): value compare
    assert_equal(reference, tested)
  end
end