Skip to content

Commit 68fa9cd

Browse files
pftgclaude
andcommitted
refactor: address multi-agent review findings
Reporter: - Rename single-letter `d` to `difference` for readability - Remove rescue ArgumentError in relative_path (fail fast per CLAUDE.md) Script: - Use reporter.finalize instead of manual File.write + render Integration test: - Extract visit to setup (DRY) - Guard @report_path nil in teardown - Use reporter.finalize instead of manual render Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b7e57a3 commit 68fa9cd

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

lib/capybara_screenshot_diff/reporters/html.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,24 @@ def self.template_path
5858
private
5959

6060
def failure_entry_for(name, compare)
61-
d = compare.difference
61+
difference = compare.difference
6262
{
6363
name: name,
6464
original: relative_path(compare.base_image_path),
6565
new: relative_path(compare.image_path),
6666
base_diff: relative_path(compare.reporter.annotated_base_image_path),
6767
diff: relative_path(compare.reporter.annotated_image_path),
6868
heatmap: relative_path(compare.reporter.heatmap_diff_path),
69-
diff_level: d.ratio && (d.ratio * 100).round(2),
70-
area_size: d.region_area_size,
71-
max_color_distance: d.meta[:max_color_distance]&.round(1)
69+
diff_level: difference.ratio && (difference.ratio * 100).round(2),
70+
area_size: difference.region_area_size,
71+
max_color_distance: difference.meta[:max_color_distance]&.round(1)
7272
}
7373
end
7474

7575
def relative_path(path)
7676
return unless path
7777

7878
Pathname.new(path).relative_path_from(@report_dir).to_s
79-
rescue ArgumentError
80-
path.to_s
8179
end
8280

8381
def write_report

scripts/generate_sample_report.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
end
4747

4848
reporter.record(assertions + passing)
49-
File.write(output_path, reporter.render)
49+
reporter.finalize
5050

51-
puts "Generated: #{output_path}"
5251
puts "Screenshots: #{reporter.failed} failed, #{reporter.passed} passed, #{reporter.total} total"

test/integration/report_screenshot_test.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,39 @@
44
require "capybara_screenshot_diff/reporters/html"
55

66
class ReportScreenshotTest < SystemTestCase
7+
PERCEPTUAL_THRESHOLD = 2.0
8+
79
setup do
810
skip "Run with RECORD_SCREENSHOTS=1 to update report fixtures" unless ENV["RECORD_SCREENSHOTS"]
911
@report_path = Pathname.new("test/fixtures/app/sample_report.html")
1012
generate_sample_report
13+
visit "/sample_report.html"
1114
end
1215

1316
teardown do
14-
FileUtils.rm_f(@report_path)
17+
FileUtils.rm_f(@report_path) if @report_path
1518
end
1619

17-
# Perceptual threshold for antialiasing differences between runs
18-
PERCEPTUAL_THRESHOLD = 2.0
19-
2020
def test_report_both_view
21-
visit "/sample_report.html"
2221
screenshot "report_both", perceptual_threshold: PERCEPTUAL_THRESHOLD
2322
end
2423

2524
def test_report_base_view
26-
visit "/sample_report.html"
2725
find("[data-view='base']").click
2826
screenshot "report_base", perceptual_threshold: PERCEPTUAL_THRESHOLD
2927
end
3028

3129
def test_report_new_view
32-
visit "/sample_report.html"
3330
find("[data-view='new']").click
3431
screenshot "report_new", perceptual_threshold: PERCEPTUAL_THRESHOLD
3532
end
3633

3734
def test_report_heatmap_view
38-
visit "/sample_report.html"
3935
find("[data-view='heatmap']").click
4036
screenshot "report_heatmap", perceptual_threshold: PERCEPTUAL_THRESHOLD
4137
end
4238

4339
def test_report_annotated_both
44-
visit "/sample_report.html"
4540
find("#annotate-toggle").click
4641
screenshot "report_annotated_both", perceptual_threshold: PERCEPTUAL_THRESHOLD
4742
end

0 commit comments

Comments
 (0)