class Simulacrum::Comparator

The Comparator class is responsible for comparing and handling processing of screenshots and candidates

Attributes

component[R]
diff[R]

Public Class Methods

new(component) click to toggle source
# File lib/simulacrum/comparator.rb, line 13
def initialize(component)
  @component = component
  component.render
end

Public Instance Methods

test() click to toggle source
# File lib/simulacrum/comparator.rb, line 18
def test
  # If the component has a reference then we should diff the candidate
  # image against the reference
  if component.reference?
    # If there is a diff between the candidate and the reference then we
    # should save both the candidate and diff images and fail the test
    (pass?) ? pass : fail

  # Otherwise we should just write the captured candidate to disk, and mark
  # the spec as being pending until the user works out if the candidate is
  # OK by renaming candidate.png to reference.png
  else
    skip
  end
end

Private Instance Methods

fail() click to toggle source
# File lib/simulacrum/comparator.rb, line 47
def fail
  diff.save(component.diff_path)
  false
end
pass() click to toggle source
# File lib/simulacrum/comparator.rb, line 41
def pass
  component.remove_candidate
  component.remove_diff
  true
end
pass?() click to toggle source
# File lib/simulacrum/comparator.rb, line 56
def pass?
  diff.delta <= component.delta_threshold
end
skip() click to toggle source
# File lib/simulacrum/comparator.rb, line 52
def skip
  nil
end