class PageSourceSnapshot

Constants

VERSION

Attributes

actual[R]
error_message[R]
expect[R]

Public Class Methods

new(expect_xml, actual_xml, ignore_attributes = []) click to toggle source
# File lib/page_source_snapshot.rb, line 8
def initialize(expect_xml, actual_xml, ignore_attributes = [])
  @expect = get_elements expect_xml, ignore_attributes
  @actual = get_elements actual_xml, ignore_attributes
  @error_message = ""
end

Public Instance Methods

compare() click to toggle source
# File lib/page_source_snapshot.rb, line 14
def compare
  message = ""
  @expect.zip(@actual).each do |e, a|
    if (e - a) != []
      message << error(e[1], a[1])
    end
  end

  @error_message = message
  @error_message.empty? ? true : false
end
error(expect, actual) click to toggle source
# File lib/page_source_snapshot.rb, line 26
def error(expect, actual)
  return if expect.nil? || actual.nil?
  return "expect: #{expect}, actual: #{actual}" unless expect.is_a?(Hash) && actual.is_a?(Hash)

  e_keys = expect.keys

  diff = {}

  e_keys.each do |key|
    if expect[key] != actual[key]
      diff[key] = "expect: #{expect[key]}, actual: #{actual[key]}"
    end
  end

  diff.empty? ? "" : "#{diff}\n"
end

Private Instance Methods

get_elements(xml, filter_attributes) click to toggle source
# File lib/page_source_snapshot.rb, line 45
def get_elements(xml, filter_attributes)
  handler = Elements.new(filter_attributes)
  Oga.sax_parse_xml(handler, xml)
  handler.elements
end