lib/capybara/screenshot/diff.rb in capybara-screenshot-diff-1.7.1 vs lib/capybara/screenshot/diff.rb in capybara-screenshot-diff-1.8.0
- old
+ new
@@ -3,14 +3,14 @@
require "capybara/dsl"
require "capybara/screenshot/diff/version"
require "capybara/screenshot/diff/drivers/utils"
require "capybara/screenshot/diff/image_compare"
require "capybara/screenshot/diff/test_methods"
+require "capybara/screenshot/diff/screenshoter"
module Capybara
module Screenshot
- extend Os
mattr_accessor :add_driver_path
mattr_accessor :add_os_path
mattr_accessor :blur_active_element
mattr_accessor :enabled
mattr_accessor :hide_caret
@@ -28,34 +28,36 @@
def active?
enabled || (enabled.nil? && Diff.enabled)
end
def screenshot_area
- parts = [Capybara::Screenshot.save_path]
- parts << Capybara.current_driver.to_s if Capybara::Screenshot.add_driver_path
- parts << os_name if Capybara::Screenshot.add_os_path
- File.join parts
+ parts = [Screenshot.save_path]
+ parts << Capybara.current_driver.to_s if Screenshot.add_driver_path
+ parts << Os.name if Screenshot.add_os_path
+ File.join(*parts)
end
def screenshot_area_abs
root / screenshot_area
end
end
# Module to track screen shot changes
module Diff
include Capybara::DSL
- include Capybara::Screenshot::Os
+ mattr_accessor(:delayed) { true }
mattr_accessor :area_size_limit
mattr_accessor :color_distance_limit
mattr_accessor(:enabled) { true }
mattr_accessor :shift_distance_limit
mattr_accessor :skip_area
mattr_accessor(:driver) { :auto }
mattr_accessor :tolerance
+ mattr_accessor(:screenshoter) { Screenshoter }
+
AVAILABLE_DRIVERS = Utils.detect_available_drivers.freeze
ASSERTION = Utils.detect_test_framework_assert
def self.default_options
{
@@ -63,41 +65,35 @@
color_distance_limit: color_distance_limit,
driver: driver,
shift_distance_limit: shift_distance_limit,
skip_area: skip_area,
stability_time_limit: Screenshot.stability_time_limit,
- tolerance: tolerance || (driver == :vips ? 0.001 : nil),
+ tolerance: tolerance || ((driver == :vips) ? 0.001 : nil),
wait: Capybara.default_max_wait_time
}
end
def self.included(klass)
klass.include TestMethods
klass.setup do
- if Capybara::Screenshot.window_size
- if page.driver.respond_to?(:resize)
- page.driver.resize(*Capybara::Screenshot.window_size)
- elsif selenium?
- page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
- end
- end
+ BrowserHelpers.resize_to(Screenshot.window_size) if Screenshot.window_size
end
klass.teardown do
- if Capybara::Screenshot.active? && @test_screenshots
+ if Screenshot.active? && @test_screenshots.present?
track_failures(@test_screenshots, caller)
- @test_screenshots = nil
+ @test_screenshots.clear
end
end
end
private
EMPTY_LINE = "\n\n"
def track_failures(screenshots, original_caller)
test_screenshot_errors = screenshots.map do |caller, name, compare|
- assert_image_not_changed(caller, name, compare)
+ assert_image_not_changed(name, compare)
end
test_screenshot_errors.compact!
unless test_screenshot_errors.empty?