Skip to content

Commit 6c396f3

Browse files
committed
🚨 Fix (actually ignore) Ruby warnings coming from other libs
1 parent 1aa0221 commit 6c396f3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spec/config/warnings.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
# Targeted silencing of a noisy deprecation coming from the oauth gem on Ruby >= 3.4.
4+
#
5+
# Example warning seen during specs:
6+
# .../gems/oauth-1.1.0/lib/oauth/helper.rb:21: warning: URI::RFC3986_PARSER.escape is obsolete. Use URI::RFC2396_PARSER.escape explicitly.
7+
#
8+
# We only filter this single message to avoid hiding other useful warnings.
9+
# This is test-only; it does not affect consumers of the library.
10+
begin
11+
original_warning_warn = Warning.method(:warn)
12+
13+
Warning.define_singleton_method(:warn) do |message|
14+
if message =~ /lib\/oauth\/helper\.rb:.*URI::RFC3986_PARSER\.escape is obsolete/
15+
# swallow this specific, known deprecation from the oauth gem
16+
nil
17+
else
18+
original_warning_warn.call(message)
19+
end
20+
end
21+
rescue StandardError # rubocop:disable Lint/SuppressedException -- best-effort; don't break older Rubies
22+
# If Warning.method(:warn) is not available on this Ruby, or redefining fails,
23+
# silently skip — tests can proceed without the filter.
24+
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Internal ENV config
77
require_relative "config/debug"
88
require_relative "config/vcr"
9+
require_relative "config/warnings"
910

1011
# RSpec config
1112
require_relative "config/rspec/rack_test"

0 commit comments

Comments
 (0)