lib/capybara/screenshot/diff.rb in capybara-screenshot-diff-1.6.2 vs lib/capybara/screenshot/diff.rb in capybara-screenshot-diff-1.6.3
- old
+ new
@@ -50,29 +50,24 @@
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) { 0.001 }
+ mattr_accessor :tolerance
AVAILABLE_DRIVERS = Utils.detect_available_drivers.freeze
- begin
- require "minitest"
- ASSERTION = Minitest::Assertion
- rescue
- ASSERTION = RuntimeError
- end
+ ASSERTION = Utils.detect_test_framework_assert
def self.default_options
{
area_size_limit: area_size_limit,
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,
+ tolerance: tolerance || (driver == :vips ? 0.001 : nil),
wait: Capybara.default_max_wait_time
}
end
def self.included(klass)
@@ -87,22 +82,34 @@
end
end
klass.teardown do
if Capybara::Screenshot.active? && @test_screenshots
- test_screenshot_errors = @test_screenshots
- .map { |caller, name, compare| assert_image_not_changed(caller, name, compare) }
- @test_screenshots = nil # release the comparison objects from memory
- test_screenshot_errors.compact!
- if test_screenshot_errors.any?
- e = ASSERTION.new(test_screenshot_errors.join("\n\n"))
- e.set_backtrace(caller)
- if defined?(failures)
- failures << e
- else
- raise e
- end
- end
+ track_failures(@test_screenshots, caller)
+ @test_screenshots = nil
+ 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)
+ end
+
+ test_screenshot_errors.compact!
+
+ unless test_screenshot_errors.empty?
+ error = ASSERTION.new(test_screenshot_errors.join(EMPTY_LINE))
+ error.set_backtrace(original_caller)
+
+ if is_a?(::Minitest::Runnable)
+ failures << error
+ else
+ raise error
end
end
end
end
end