Skip to content

Commit c89b34c

Browse files
committed
Add spec for Kernel#warn when called from a #require-d file
1 parent 57c5fd6 commit c89b34c

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
warn 'warn-require-warning', uplevel: 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Use a different line than just 1
2+
require "#{__dir__}/warn_require"

spec/ruby/core/kernel/warn_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@
101101
-> { w.f4("foo", 3) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f3_call_lineno}: warning: foo|)
102102
end
103103

104+
# Test both explicitly without and with RubyGems as RubyGems overrides Kernel#warn
105+
it "shows the caller of #require and not #require itself without RubyGems" do
106+
file = fixture(__FILE__ , "warn_require_caller.rb")
107+
ruby_exe(file, options: "--disable-gems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
108+
end
109+
110+
ruby_version_is "2.6" do
111+
it "shows the caller of #require and not #require itself with RubyGems loaded" do
112+
file = fixture(__FILE__ , "warn_require_caller.rb")
113+
ruby_exe(file, options: "-rrubygems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
114+
end
115+
end
116+
104117
it "converts first arg using to_s" do
105118
w = KernelSpecs::WarnInNestedCall.new
106119

spec/tags/core/kernel/warn_tags.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
slow:Kernel#warn :uplevel keyword argument shows the caller of #require and not #require itself without RubyGems
2+
slow:Kernel#warn :uplevel keyword argument shows the caller of #require and not #require itself with RubyGems loaded

0 commit comments

Comments
 (0)