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

Returns a new instance of Comparator.



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

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

Instance Attribute Details

#candidateObject

Returns the value of attribute candidate.



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

def candidate
  @candidate
end

#componentObject

Returns the value of attribute component.



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

def component
  @component
end

#diffObject

Returns the value of attribute diff.



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

def diff
  @diff
end

Instance Method Details

#testObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simulacrum/comparator.rb', line 17

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
    perform_diff ? 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