Skip to content

Commit

Permalink
Add support for Kernel#warn.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 5, 2024
1 parent 039d7f0 commit 2c542e0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@

gem "bake-test"
gem "bake-test-external"

gem "sus-fixtures-console"
end
1 change: 1 addition & 0 deletions lib/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

require_relative 'console/version'
require_relative 'console/logger'
require_relative 'console/warn'

module Console
class << self
Expand Down
18 changes: 18 additions & 0 deletions lib/console/warn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

module Console
module Warn
def warn(*arguments, uplevel: nil, **options)
if uplevel
options[:backtrace] = caller(uplevel, 1)
end

Console.warn(*arguments, **options)
end
end

::Kernel.prepend(Warn)
end
24 changes: 24 additions & 0 deletions test/console/warn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'sus/fixtures/console'

describe "Kernel#warn" do
include_context Sus::Fixtures::Console::CapturedLogger

it "redirects to Console.warn" do
warn "It did not work as expected!"

expect(console_capture.last).to have_keys(
severity: be == :warn,
subject: be == "It did not work as expected!"
)
end

it "supports uplevel" do
warn "It did not work as expected!", uplevel: 1

expect(console_capture.last).to have_keys(
severity: be == :warn,
subject: be == "It did not work as expected!",
backtrace: be_a(Array)
)
end
end

0 comments on commit 2c542e0

Please sign in to comment.