summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/util_spec.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-09-29 09:15:43 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-29 10:34:07 -0700
commit869e4f6e4c683bf8e76ae7db54a26b33fb925410 (patch)
tree4985302b04065eb0e42156006f60d8b191632e6b /spec/ruby/optional/capi/util_spec.rb
parent070cbe22b70ec2bec36c7cfc84b726510afa306f (diff)
Fix or suppress keyword argument separation warnings in util_spec
Some warnings are because the @o.rb_scan_args call doesn't include keyword arguments, but the first argument is passed to rb_scan_args may have a last hash treated as keywords. Those should be handled using rb_scan_args_kw on Ruby 2.7. Other warnings are for the deprecated rb_scan_args behavior to split option hashes or treat a nil argument as an option hash. Those warnings should just be suppressed.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2504
Diffstat (limited to 'spec/ruby/optional/capi/util_spec.rb')
-rw-r--r--spec/ruby/optional/capi/util_spec.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb
index ee48e2e0ea..3556c8c010 100644
--- a/spec/ruby/optional/capi/util_spec.rb
+++ b/spec/ruby/optional/capi/util_spec.rb
@@ -11,6 +11,7 @@ describe "C-API Util function" do
before :each do
@prc = -> { 1 }
@acc = []
+ @keyword_prefix = 'k' if RUBY_VERSION >= '2.7'
ScratchPad.record @acc
end
@@ -99,13 +100,13 @@ describe "C-API Util function" do
it "assigns Hash arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([h], "0:", 1, @acc).should == 0
+ @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc).should == 0
ScratchPad.recorded.should == [h]
end
it "assigns required and Hash arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([1, h], "1:", 2, @acc).should == 1
+ @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc).should == 1
ScratchPad.recorded.should == [1, h]
end
@@ -115,7 +116,9 @@ describe "C-API Util function" do
end
it "assigns required and Hash arguments with nil Hash" do
- @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1
+ suppress_warning do
+ @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1
+ end
ScratchPad.recorded.should == [1, nil]
end
@@ -126,7 +129,7 @@ describe "C-API Util function" do
it "assigns required, optional, splat, post-splat, Hash and block arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "11*1:&", 6, @acc, &@prc).should == 5
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 5
ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc]
end
@@ -134,7 +137,9 @@ describe "C-API Util function" do
it "rejects non-keyword arguments" do
h = {1 => 2, 3 => 4}
-> {
- @o.rb_scan_args([h], "0:", 1, @acc)
+ suppress_warning do
+ @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc)
+ end
}.should raise_error(ArgumentError)
ScratchPad.recorded.should == []
end
@@ -142,14 +147,18 @@ describe "C-API Util function" do
it "rejects required and non-keyword arguments" do
h = {1 => 2, 3 => 4}
-> {
- @o.rb_scan_args([1, h], "1:", 2, @acc)
+ suppress_warning do
+ @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc)
+ end
}.should raise_error(ArgumentError)
ScratchPad.recorded.should == []
end
it "considers the hash as a post argument when there is a splat" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "11*1:&", 6, @acc, &@prc).should == 6
+ suppress_warning do
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 6
+ end
ScratchPad.recorded.should == [1, 2, [3, 4, 5], h, nil, @prc]
end
end