Skip to content

Commit

Permalink
Merge pull request #82 from fastruby/bug/fix-warn-override-signature
Browse files Browse the repository at this point in the history
Update `KernelWarnTracker#warn` signature to match `Kernel#warn`
  • Loading branch information
etagwerker authored Mar 3, 2023
2 parents 0f23fbd + 5b9bfd1 commit 3eb41a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 6 additions & 2 deletions lib/deprecation_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions spec/deprecation_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 3eb41a2

Please sign in to comment.