diff --git a/CHANGELOG.md b/CHANGELOG.md index afe0303..8e168d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.2.1...main) +* [BUGFIX: Fixed `KernelWarnTracker#warn signature to match `Kernel#warn` for ruby 2.5+](https://github.com/fastruby/next_rails/pull/82) * [CHORE: Added updated templates for bug fixes, feature requests and pull requests](https://github.com/fastruby/next_rails/pull/64) as per [this RFC](https://github.com/fastruby/RFCs/blob/main/2021-10-13-github-templates.md) * [FEATURE: Turn BundleReport into a module](https://github.com/fastruby/next_rails/pull/63) diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index ed60506..adc005f 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -18,12 +18,16 @@ def self.callbacks @callbacks ||= [] end - def warn(*messages) + def warn(*messages, uplevel: nil) KernelWarnTracker.callbacks.each do |callback| messages.each { |message| callback.(message) } end - super + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0") + super *messages + else + super + end end end diff --git a/spec/deprecation_tracker_spec.rb b/spec/deprecation_tracker_spec.rb index 7f49c42..e017c0c 100644 --- a/spec/deprecation_tracker_spec.rb +++ b/spec/deprecation_tracker_spec.rb @@ -2,6 +2,8 @@ require_relative "spec_helper" require_relative "../lib/deprecation_tracker" +RSpec::Matchers.define_negated_matcher :not_raise_error, :raise_error + RSpec.describe DeprecationTracker do let(:shitlist_path) do shitlist_path = Tempfile.new("tmp").path @@ -269,5 +271,18 @@ expect(warn_messages).to eq(["oh", "no"]) end + + describe "bug when warning uses the uplevel keyword argument" do + context "given I setup the DeprecationTracker::KernelWarnTracker with a callback that manipulates messages as Strings" do + + DeprecationTracker::KernelWarnTracker.callbacks << -> (message) { message.gsub("Rails.root/", "") } + + context "and given that I call code that emits a warning using the uplevel keyword arg" do + it "throws a MissingMethod Error" do + expect { Kernel.warn("Oh no", uplevel: 1) }.to not_raise_error.and output.to_stderr + end + end + end + end end end