tests: suppress phlex's gem warnings in test output
The test task runs ruby -w, under which phlex 2.4.1's own files
compile into a page of warnings that drowned the suite's own.
Suppression is path-scoped to the gem install directory via a
Warning.warn alias chain, so app-code warnings still surface.
Assisted-by: GLM-5.3 via pi
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 29cb674..236c589 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -42,6 +42,35 @@ Minitest.after_run { FileUtils.rm_rf(unhandled_dir) }
ENV["PRO_TACTS_DEBUG_LOG"] ||= "log/test.log"
File.truncate("log/test.log", 0) if File.exist?("log/test.log")
+# The interpreter runs with -w (the test task's flag), and phlex's own
+# files compile under it into a stream of warnings — mismatched
+# indentations, a method-redefined pair for every void element — none
+# of it app code. Suppressed here, path-scoped to the gem's install
+# directory rather than globally, so this suite's own warnings (an
+# ambiguous `/` in test_store.rb, say) still surface. Defined after the
+# ENV block but before the first require that loads phlex: the spec
+# lookup finds the path without requiring the gem, and the override is
+# in place before phlex's files ever compile. Nothing later in this
+# file or the suite re-overrides Warning.warn, so the chain holds.
+module PhlexWarningFilter
+ PHLEX_PATH = Gem::Specification.find_by_name("phlex").full_gem_path
+
+ #: (String message) -> bool
+ def self.from_phlex?(message)
+ message.start_with?("#{PHLEX_PATH}/")
+ end
+end
+
+module Warning
+ class << self
+ alias_method :warn_without_phlex_filter, :warn
+ end
+
+ def self.warn(message, **kwargs)
+ warn_without_phlex_filter(message, **kwargs) unless PhlexWarningFilter.from_phlex?(message)
+ end
+end
+
require_relative "fixture_data"
require "pro_tacts/web"
require "minitest/autorun"
diff --git a/test/test_phlex_warning_filter.rb b/test/test_phlex_warning_filter.rb
new file mode 100644
index 0000000..9276959
--- /dev/null
+++ b/test/test_phlex_warning_filter.rb
@@ -0,0 +1,19 @@
+require_relative "test_helper"
+
+# The path predicate behind the Warning.warn override in test_helper:
+# phlex's install directory and nothing else. The trailing slash in the
+# comparison is what keeps a hypothetical neighboring gem (a phlex-foo,
+# installed beside phlex) from matching on prefix alone. The override's
+# wiring is not asserted here — calling Warning.warn from a test would
+# print the very warnings this suite suppresses — so the wiring is
+# verified by the test run's own output instead.
+class PhlexWarningFilterTest < Minitest::Test
+ def test_matches_only_messages_from_phlex_install_path
+ phlex = "#{PhlexWarningFilter::PHLEX_PATH}/lib/phlex/html.rb:84: " \
+ "warning: mismatched indentations at 'elsif' with 'if' at 58"
+ assert PhlexWarningFilter.from_phlex?(phlex)
+
+ app = "test/pro_tacts/test_store.rb:626: warning: ambiguous `/`"
+ refute PhlexWarningFilter.from_phlex?(app)
+ end
+end