Skip to content

Commit b359e18

Browse files
Earlopaineregon
authored andcommitted
Move generic format/sprintf warn specs to shared examples
Also use the `complain` matcher instead of `ruby_exe`
1 parent 107cbd2 commit b359e18

2 files changed

Lines changed: 23 additions & 32 deletions

File tree

core/kernel/format_spec.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,4 @@
1212
it "is accessible as a module function" do
1313
Kernel.format("%s", "hello").should == "hello"
1414
end
15-
16-
describe "when $VERBOSE is true" do
17-
it "warns if too many arguments are passed" do
18-
code = <<~RUBY
19-
$VERBOSE = true
20-
format("test", 1)
21-
RUBY
22-
23-
ruby_exe(code, args: "2>&1").should.include?("warning: too many arguments for format string")
24-
end
25-
26-
it "does not warns if too many keyword arguments are passed" do
27-
code = <<~RUBY
28-
$VERBOSE = true
29-
format("test %{test}", test: 1, unused: 2)
30-
RUBY
31-
32-
ruby_exe(code, args: "2>&1").should_not.include?("warning")
33-
end
34-
35-
ruby_bug "#20593", ""..."3.4" do
36-
it "doesn't warns if keyword arguments are passed and none are used" do
37-
code = <<~RUBY
38-
$VERBOSE = true
39-
format("test", test: 1)
40-
format("test", {})
41-
RUBY
42-
43-
ruby_exe(code, args: "2>&1").should_not.include?("warning")
44-
end
45-
end
46-
end
4715
end

core/kernel/shared/sprintf.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,4 +1031,27 @@ def obj.to_str; end
10311031
it "does not raise error when passed more arguments than needed" do
10321032
sprintf("%s %d %c", "string", 2, "c", []).should == "string 2 c"
10331033
end
1034+
1035+
describe "when $VERBOSE is true" do
1036+
it "warns if too many arguments are passed" do
1037+
-> {
1038+
format("test", 1)
1039+
}.should complain(/too many arguments for format string/, verbose: true)
1040+
end
1041+
1042+
it "does not warns if too many keyword arguments are passed" do
1043+
-> {
1044+
format("test %{test}", test: 1, unused: 2)
1045+
}.should_not complain(verbose: true)
1046+
end
1047+
1048+
ruby_bug "#20593", ""..."3.4" do
1049+
it "doesn't warns if keyword arguments are passed and none are used" do
1050+
-> {
1051+
format("test", test: 1)
1052+
format("test", {})
1053+
}.should_not complain(verbose: true)
1054+
end
1055+
end
1056+
end
10341057
end

0 commit comments

Comments
 (0)