Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [BUGFIX: example](https://github.com/fastruby/next_rails/pull/<number>)
- [CHORE: Create an entry point for the BundleReport command](https://github.com/fastruby/next_rails/pull/154)
- [CHORE: Bring back support of Ruby 2.3, 2.4 and 2.5](https://github.com/fastruby/next_rails/pull/155)
- [BUFIX: deprecation_tracker breaking with unknown keywords](https://github.com/fastruby/next_rails/pull/158)

* Your changes/patches go here.

Expand Down
21 changes: 13 additions & 8 deletions lib/deprecation_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ def self.callbacks
@callbacks ||= []
end

def warn(*messages, uplevel: nil, category: nil)
def warn(*messages, uplevel: nil, category: nil, **kwargs)
KernelWarnTracker.callbacks.each do |callback|
messages.each { |message| callback.(message) }
messages.each { |message| callback.call(message) }
end

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0")
super(*messages)
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
super(*messages, uplevel: nil)
ruby_version = Gem::Version.new(RUBY_VERSION)

if ruby_version >= Gem::Version.new("3.2.0")
# Kernel#warn supports uplevel, category
super(*messages, uplevel: uplevel, category: category)
elsif ruby_version >= Gem::Version.new("2.5.0")
# Kernel#warn supports only uplevel
super(*messages, uplevel: uplevel)
else
super
# No keyword args supported
super(*messages)
end
end
end
Expand All @@ -43,7 +48,7 @@ def before_setup
@@deprecation_tracker.bucket = test_file_name.gsub(Rails.root.to_s, ".")
super
end

def after_teardown
super
@@deprecation_tracker.bucket = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/next_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module NextRails
VERSION = "1.4.6"
VERSION = "1.4.7"
end
31 changes: 31 additions & 0 deletions spec/deprecation_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ def self.behavior
end

describe DeprecationTracker::KernelWarnTracker do
before { DeprecationTracker::KernelWarnTracker.callbacks.clear }

it "captures Kernel#warn" do
warn_messages = []
DeprecationTracker::KernelWarnTracker.callbacks << -> (message) { warn_messages << message }
Expand Down Expand Up @@ -330,5 +332,34 @@ def self.behavior
end
end
end

describe "bug when warning uses unexpected keyword arguments" do
it "does not raise an error with unknown keyword args like :deprecation, :span, :stack" do
DeprecationTracker::KernelWarnTracker.callbacks << -> (message) { message.to_s }

expect {
warn("Unknown deprecation warning", deprecation: true, span: 1.2, stack: ["line1", "line2"])
}.to not_raise_error.and output.to_stderr
end
end

it "handles known and unknown keyword arguments without raising" do
warnings = []
DeprecationTracker::KernelWarnTracker.callbacks << ->(msg) { warnings << msg }

expect {
warn(
"This is a test warning",
uplevel: 1,
category: :deprecated,
deprecation: true,
span: 1.2,
stack: ["line"]
)
}.to not_raise_error

expect(warnings).to include("This is a test warning")
end

end
end