lib/cucumber-rest-bdd/steps/response.rb
def nest_match(data, nesting, expected)
    return false if !data
    return data.deep_include?(expected) if nesting.size == 0

    local_nesting = nesting.dup
    level = local_nesting.pop
    case level[:type]
    when 'single' then
        child_data = level[:root] ? data.dup : data[get_parameter(level[:key])]
        return nest_match(child_data, local_nesting, expected)
    when 'multiple' then
        child_data = level[:root] ? data.dup : data[get_resource(level[:key])]
        matched = child_data.select { |item| nest_match(item, local_nesting, expected) }
        return num_compare(level[:count_mod], matched.count, level[:count])
    when 'list' then
        child_data = level[:root] ? data.dup : data[get_resource(level[:key])]
        return false if !child_data.is_a?(Array)
        if level.has_key?(:count) then
            return num_compare(level[:count_mod], child_data.count, level[:count])
        end
        return true
    else
        raise %/Unknown nested data type: #{level[:type]}/
    end
end
# top level has 2 children with an item containing at most three fish with attributes:
#
# nesting = [{key=fish,count=3,count_mod='<=',type=multiple},{key=item,type=single},{key=children,type=multiple,count=2,count_mod='='},{root=true,type=single}]
#
# returns true if the expected data is contained within the data based on the nesting information


returns true if the expected data is contained within the data based on the nesting information
returns true if the expected data is contained within the data based on the nesting information
def nest_match(data, nesting, expected)
    return false if !data
    return data.deep_include?(expected) if nesting.size == 0
    local_nesting = nesting.dup
    level = local_nesting.pop
    case level[:type]
    when 'single' then
        child_data = level[:root] ? data.dup : data[get_parameter(level[:key])]
        return nest_match(child_data, local_nesting, expected)
    when 'multiple' then
        child_data = level[:root] ? data.dup : data[get_resource(level[:key])]
        matched = child_data.select { |item| nest_match(item, local_nesting, expected) }
        return num_compare(level[:count_mod], matched.count, level[:count])
    when 'list' then
        child_data = level[:root] ? data.dup : data[get_resource(level[:key])]
        return false if !child_data.is_a?(Array)
        if level.has_key?(:count) then
            return num_compare(level[:count_mod], child_data.count, level[:count])
        end
        return true
    else
        raise %/Unknown nested data type: #{level[:type]}/
    end
end
def nest_match ( data , nesting , expected ) return false if ! data return data . deep_include? ( expected ) if nesting . size == 0 local_nesting = nesting . dup level = local_nesting . pop case level [ :type ] when 'single' then child_data = level [ :root ] ? data . dup : data [ get_parameter ( level [ :key ] ) ] return nest_match ( child_data , local_nesting , expected ) when 'multiple' then child_data = level [ :root ] ? data . dup : data [ get_resource ( level [ :key ] ) ] matched = child_data . select { | item | nest_match ( item , local_nesting , expected ) } return num_compare ( level [ :count_mod ] , matched . count , level [ :count ] ) when 'list' then child_data = level [ :root ] ? data . dup : data [ get_resource ( level [ :key ] ) ] return false if ! child_data . is_a? ( Array ) if level . has_key? ( :count ) then return num_compare ( level [ :count_mod ] , child_data . count , level [ :count ] ) end return true else raise %/Unknown nested data type: #{level[:type]}/ end end
top level has 2 children with an item containing at most three fish with attributes:
nesting = [{key=fish,count=3,count_mod='<=',type=multiple},{key=item,type=single},{key=children,type=multiple,count=2,count_mod='='},{root=true,type=single}]
top level has 2 children with an item containing at most three fish with attributes : nesting = [ { key = fish count = 3 count_mod = ' < = ' type = multiple } { key = item type = single } { key = children type = multiple count = 2 count_mod = ' = ' } { root = true type = single } ]
data
nesting
expected