Class: Guardrails::VisualDiff::SnapDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/guardrails/visual_diff/snap_diff.rb

Overview

Adapter for snap_diff-capybara (formerly capybara-screenshot-diff). The gem commits baselines to git under ‘doc/screenshots/` by convention. After a failed run there’s a ‘<name>.diff.png` sibling next to `<name>.png`. Walking the directory tree and pairing names gives us a binary pass/fail per scenario without needing snap_diff to emit a JSON report (see upstream issue — TODO: link once filed).

Limits:

  • No mismatch percentage; snap_diff is binary at the filesystem level. Findings emit ‘mismatch_ratio: nil` and VisualDiff treats nil as “unconditionally failing” (any diff fails).

  • No URL / viewport / selector — those live in snap_diff’s Capybara tests, not the artifact tree. Adapters that have them (BackstopJS, issue #15) populate the optional fields.

Constant Summary collapse

DIFF_SUFFIX =
".diff.png"
HEATMAP_SUFFIX =
".heatmap.diff.png"

Instance Method Summary collapse

Constructor Details

#initialize(root:, dir:) ⇒ SnapDiff

Returns a new instance of SnapDiff.



25
26
27
28
# File 'lib/guardrails/visual_diff/snap_diff.rb', line 25

def initialize(root:, dir:)
  @root = Pathname(root)
  @dir = @root.join(dir)
end

Instance Method Details

#collectObject



30
31
32
33
34
# File 'lib/guardrails/visual_diff/snap_diff.rb', line 30

def collect
  return [] unless @dir.directory?

  diff_files.map { |diff| build_finding(diff) }.compact
end