Skip to content

Commit d9cfd39

Browse files
pftgclaude
andcommitted
refactor: unify Screenshoter constructor to accept comparison_options
Both Screenshoter and StableScreenshoter now accept the same (capture_options, comparison_options) signature. Eliminates the asymmetry where one received a driver instance and the other a hash. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6473e09 commit d9cfd39

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

lib/capybara/screenshot/diff/screenshot_matcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def capture_screenshot(capture_options, comparison_options)
8383
screenshoter = if capture_options[:stability_time_limit]
8484
StableScreenshoter.new(capture_options, comparison_options)
8585
else
86-
Diff.screenshoter.new(capture_options, comparison_options[:driver])
86+
Diff.screenshoter.new(capture_options, comparison_options)
8787
end
8888
screenshoter.take_comparison_screenshot(@snapshot)
8989
end

lib/capybara/screenshot/diff/screenshoter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module Screenshot
88
class Screenshoter
99
attr_reader :capture_options, :driver
1010

11-
def initialize(capture_options, driver)
11+
def initialize(capture_options, comparison_options = {})
1212
@capture_options = capture_options
13-
@driver = driver
13+
@driver = Diff::Drivers.for(comparison_options)
1414
end
1515

1616
def crop

lib/capybara/screenshot/diff/stable_screenshoter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def initialize(capture_options, comparison_options = {})
2525

2626
@comparison_options = comparison_options
2727

28-
driver = Diff::Drivers.for(@comparison_options)
29-
@screenshoter = Diff.screenshoter.new(capture_options.except(:stability_time_limit), driver)
28+
@screenshoter = Diff.screenshoter.new(capture_options.except(:stability_time_limit), @comparison_options)
3029
end
3130

3231
# Takes a comparison screenshot ensuring page stability

test/unit/screenshoter_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ScreenshoterTest < ActiveSupport::TestCase
1010
include CapybaraScreenshotDiff::DSLStub
1111

1212
test "#take_screenshot without wait skips image loading" do
13-
screenshoter = Screenshoter.new({wait: nil}, ::Minitest::Mock.new)
13+
screenshoter = Screenshoter.new({wait: nil}, {driver: :chunky_png})
1414

1515
mock = ::Minitest::Mock.new
1616
mock.expect(:save_screenshot, true) { |path| path.include?("01_a.png") }
@@ -27,7 +27,7 @@ class ScreenshoterTest < ActiveSupport::TestCase
2727
test "#take_screenshot with custom screenshot options" do
2828
screenshoter = Screenshoter.new(
2929
{wait: nil, capybara_screenshot_options: {full: true}},
30-
::Minitest::Mock.new
30+
{driver: :chunky_png}
3131
)
3232

3333
mock = ::Minitest::Mock.new
@@ -43,7 +43,7 @@ class ScreenshoterTest < ActiveSupport::TestCase
4343
end
4444

4545
test "#prepare_page_for_screenshot without wait does not raise any error" do
46-
screenshoter = Screenshoter.new({wait: nil}, ::Minitest::Mock.new)
46+
screenshoter = Screenshoter.new({wait: nil}, {driver: :chunky_png})
4747

4848
assert_nil screenshoter.prepare_page_for_screenshot(timeout: nil) # does not raise an error
4949
end

0 commit comments

Comments
 (0)