Skip to content

Commit

Permalink
refact: use build
Browse files Browse the repository at this point in the history
  • Loading branch information
pftg committed Dec 10, 2023
1 parent a3b6832 commit 7a0da8e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/capybara/screenshot/diff/screenshot_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def build_screenshot_matches_job
# Add comparison job in the queue
[
screenshot_full_name,
ImageCompare.new(screenshot_path.to_s, base_screenshot_path.to_s, driver_options)
ImageCompare.build(screenshot_path.to_s, base_screenshot_path.to_s, driver_options)
]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/screenshot/diff/stable_screenshoter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def take_stable_screenshot(screenshot_path)
private

def build_comparison_for(attempt_path, previous_attempt_path)
ImageCompare.new(attempt_path, previous_attempt_path, @comparison_options)
ImageCompare.build(attempt_path, previous_attempt_path, @comparison_options)
end

def annotate_attempts_and_fail!(screenshot_path)
Expand Down
2 changes: 1 addition & 1 deletion scripts/benchmark/find_region_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def for_small_images
def experiment_for(x, driver, method, suffix, new_path, base_path)
x.report("[#{suffix}] #{driver}##{method}") do
50.times do
ImageCompare.new(new_path, base_path, driver: driver).public_send(method)
ImageCompare.build(new_path, base_path, driver: driver).public_send(method)

Vips.cache_set_max(0)
Vips.cache_set_max(1000)
Expand Down
14 changes: 7 additions & 7 deletions test/capybara/screenshot/diff/image_compare_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ class ImageCompareTest < ActionDispatch::IntegrationTest
include TestMethodsStub

test "it can be instantiated with chunky_png driver" do
comparison = ImageCompare.new("images/b.png", "images/b.base.png")
comparison = ImageCompare.build("images/b.png", "images/b.base.png")
assert_kind_of Drivers::ChunkyPNGDriver, comparison.driver
end

test "it can be instantiated with explicit chunky_png adapter" do
comparison = ImageCompare.new("images/b.png", "images/b.base.png", driver: :chunky_png)
comparison = ImageCompare.build("images/b.png", "images/b.base.png", driver: :chunky_png)
assert_kind_of Drivers::ChunkyPNGDriver, comparison.driver
end

test "it can be instantiated with vips adapter" do
skip "VIPS not present. Skipping VIPS driver tests." unless defined?(Vips)
comparison = ImageCompare.new("images/b.png", "images/b.base.png", driver: :vips)
comparison = ImageCompare.build("images/b.png", "images/b.base.png", driver: :vips)
assert_kind_of Drivers::VipsDriver, comparison.driver
end

Expand Down Expand Up @@ -60,23 +60,23 @@ class ImageCompareTest < ActionDispatch::IntegrationTest
end

test "could pass use tolerance for chunky_png driver" do
ImageCompare.new("images/b.png", "images/b.base.png", driver: :chunky_png, tolerance: 0.02)
ImageCompare.build("images/b.png", "images/b.base.png", driver: :chunky_png, tolerance: 0.02)
end

test "it can be instantiated with dimensions" do
assert ImageCompare.new("images/b.png", "images/b.base.png", dimensions: [80, 80])
assert ImageCompare.build("images/b.png", "images/b.base.png", dimensions: [80, 80])
end

test "for driver: :auto returns first from available drivers" do
skip "VIPS not present. Skipping VIPS driver tests." unless defined?(Vips)
comparison = ImageCompare.new("images/b.png", "images/b.base.png", driver: :auto)
comparison = ImageCompare.build("images/b.png", "images/b.base.png", driver: :auto)
assert_kind_of Drivers::VipsDriver, comparison.driver
end

test "for driver: :auto raise error if no drivers are available" do
Capybara::Screenshot::Diff.stub_const(:AVAILABLE_DRIVERS, []) do
assert_raise(RuntimeError) do
ImageCompare.new("images/b.png", "images/b.base.png", driver: :auto)
ImageCompare.build("images/b.png", "images/b.base.png", driver: :auto)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/support/stub_test_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def make_comparison(fixture_base_image, fixture_new_image, destination: nil, **o

set_test_images(destination, fixture_base_image, fixture_new_image)

ImageCompare.new(destination, ScreenshotMatcher.base_image_path_from(destination), **options)
ImageCompare.build(destination, ScreenshotMatcher.base_image_path_from(destination), **options)
end

def set_test_images(destination, original_base_image, original_new_image)
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ def optional_test

def assert_same_images(expected_image_name, image_path)
expected_image_path = file_fixture("files/comparisons/#{expected_image_name}")
assert_predicate(Capybara::Screenshot::Diff::ImageCompare.new(image_path, expected_image_path), :quick_equal?)
assert_predicate(Capybara::Screenshot::Diff::ImageCompare.build(image_path, expected_image_path), :quick_equal?)
end
end

0 comments on commit 7a0da8e

Please sign in to comment.