From ac5baba4a49b84aa48be39bea7831fbd4e3d501b Mon Sep 17 00:00:00 2001 From: Paul Keen <125715+pftg@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:13:59 +0200 Subject: [PATCH] refact: shows deprecation message only when minitest required automatically --- lib/capybara-screenshot-diff.rb | 8 -------- lib/capybara/screenshot/diff.rb | 8 -------- lib/capybara_screenshot_diff/minitest.rb | 11 +++++++++++ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/capybara-screenshot-diff.rb b/lib/capybara-screenshot-diff.rb index 96f75baf..dff8d102 100644 --- a/lib/capybara-screenshot-diff.rb +++ b/lib/capybara-screenshot-diff.rb @@ -1,11 +1,3 @@ # frozen_string_literal: true -warn <<~MSG - - DEPRECATED: use 'require "capybara_screenshot_diff/minitest"' instead of 'require "capybara-screenshot-diff"' - in #{caller(3)&.first}. - "capybara-screenshot-diff" is no longer needed and will be removed in the next major release. - -MSG - require "capybara_screenshot_diff/minitest" diff --git a/lib/capybara/screenshot/diff.rb b/lib/capybara/screenshot/diff.rb index e3664282..dff8d102 100644 --- a/lib/capybara/screenshot/diff.rb +++ b/lib/capybara/screenshot/diff.rb @@ -1,11 +1,3 @@ # frozen_string_literal: true -warn <<~MSG - - DEPRECATED: use 'require "capybara_screenshot_diff/minitest"' or 'require "capybara_screenshot_diff/rspec"' instead of 'require "capybara/screenshot/diff"' - in #{caller(3)&.first}. - "capybara/screenshot/diff" is no longer needed and will be removed in the next major release. - -MSG - require "capybara_screenshot_diff/minitest" diff --git a/lib/capybara_screenshot_diff/minitest.rb b/lib/capybara_screenshot_diff/minitest.rb index cf2f90d7..c3e2b9ab 100644 --- a/lib/capybara_screenshot_diff/minitest.rb +++ b/lib/capybara_screenshot_diff/minitest.rb @@ -3,6 +3,17 @@ require "minitest" require "capybara_screenshot_diff/dsl" +used_deprecated_entrypoint = caller.any? do |path| + path.include?("capybara-screenshot-diff.rb") || path.include?("capybara/screenshot/diff.rb") +end + +if used_deprecated_entrypoint + warn <<~MSG + [DEPRECATION] The default activation of `capybara_screenshot_diff/minitest` will be removed. + Please `require "capybara_screenshot_diff/minitest"` explicitly. + MSG +end + module CapybaraScreenshotDiff module Minitest module Assertions