Matching key,values of Hash of Hash in script with key,values of Array of Hash got from the page is

I wrote a Ruby script to check if the layer found in DOM in Firebug for
the page www.jira.com is matching with the hash values declared in my
script. Below is the Ruby script I have written:

browser.goto('www.jira.com')

JIRA_DATA_LAYER = {
    'one' => {
              'event'     => 'gtm.js',
              'gtm.start' => 1468393184212,
             },
    'two' => {
              'event'     => 'gtm.start',
              'gtm.start' => 1468332746325,
             },
    'three' => {
              'event'     => 'gtm.load',
              'gtm.load'  => 1468483543548,
             },
}

def read_data_layer(browser)
    data_layer = browser.execute_script("return dataLayer")

    return data_layer
end

def compare_jira_data_layer(browser)
    result = []

    compare_data_layer = read_data_layer(browser)

    compare_data_layer[0].each do |key,value|
       result.push(key)
    end

    return result.join("\n")
end

Following part of the code is not working:
-------------------------------------------------------------------------
def jira_data_layer(browser, layer)
    message = []

    result_compare = compare_jira_data_layer(browser)

    message.push('Checking Jira Data Layer')

    JIRA_DATA_LAYER.each do |key, value|
        value.each do |data_layer_key, data_layer_value|
            if data_layer_value == result_compare
                result = 'matches - PASS'
            else
                result = 'does not match - FAIL'
            end

            message.push("#{data_layer_key} #{result}")
        end
    end

    return message.join("\n")
end
-------------------------------------------------------------------------

data_layer = read_data_layer(browser)

puts jira_data_layer(browser, data_layer)

I want the following OUTPUT to be achieved:

'event => gtm.js' matches - PASS
'gtm.start => 1468393184212' matches - PASS

But I am getting this:

event does not match - FAIL
gtm.start does not match - FAIL

Where am I going wrong? Please help. Thanks in advance

Lets focus on the first iteration of your value.each loop.
data_layer_key equals ‘event’ and data_layer_value equals ‘gtm.js’.

In message.push, you first output data_layer_key, which is ‘event’, and
then the result of the comparision. You did not write which value
result_compare has, but obviously it has a value different from
‘gtm.js’. Hence the output you get.

Reasoning about the second iteration is similar.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs