Skip to content

Commit 0d37b4a

Browse files
pftgclaude
andcommitted
fix: defer output_path computation to avoid save_path timing bug
Codex review found: auto-registered reporter captured save_path at require time (before user configures it in test_helper.rb). Now output_path is lazy — computed on first access, after config is set. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 24fe3c1 commit 0d37b4a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • lib/capybara_screenshot_diff/reporters

lib/capybara_screenshot_diff/reporters/html.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
module CapybaraScreenshotDiff
1010
module Reporters
1111
class HTML
12-
attr_reader :output_path, :failures, :total
12+
attr_reader :failures, :total
1313

1414
def initialize(output_path: nil, embed_images: false)
15-
@output_path = Pathname.new(output_path || self.class.default_output_path)
16-
@report_dir = @output_path.dirname
15+
@explicit_output_path = output_path
1716
@embed_images = embed_images
1817
@failures = []
1918
@total = 0
@@ -44,6 +43,10 @@ def finalize
4443
output_path
4544
end
4645

46+
def output_path
47+
@output_path ||= Pathname.new(@explicit_output_path || self.class.default_output_path)
48+
end
49+
4750
def passed = total - failures.size
4851
def failed = failures.size
4952

@@ -88,7 +91,7 @@ def resolve_image(path)
8891
pathname = Pathname.new(path).expand_path
8992
return unless pathname.exist?
9093

91-
@embed_images ? data_uri(pathname) : pathname.relative_path_from(@report_dir.expand_path).to_s
94+
@embed_images ? data_uri(pathname) : pathname.relative_path_from(output_path.dirname.expand_path).to_s
9295
end
9396

9497
def data_uri(pathname)
@@ -98,7 +101,7 @@ def data_uri(pathname)
98101
end
99102

100103
def write_report
101-
FileUtils.mkdir_p(@report_dir)
104+
FileUtils.mkdir_p(output_path.dirname)
102105
File.write(output_path, render)
103106
end
104107
end

0 commit comments

Comments
 (0)