Class: Simulacrum::Comparator

Inherits:
Object
  • Object
show all
Includes:
RSpec::Core::Pending
Defined in:
lib/simulacrum/comparator.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ Comparator



13
14
15
16
# File 'lib/simulacrum/comparator.rb', line 13

def initialize(component)
  @component = component
  component.render
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



11
12
13
# File 'lib/simulacrum/comparator.rb', line 11

def component
  @component
end

#diffObject (readonly)

Returns the value of attribute diff.



11
12
13
# File 'lib/simulacrum/comparator.rb', line 11

def diff
  @diff
end

Instance Method Details

#testObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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