Skip to content

Commit cc05a60

Browse files
committed
1 parent acab060 commit cc05a60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+480
-128
lines changed

spec/ruby/core/array/assoc_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@
3737
a.assoc(s1.first).should equal(s1)
3838
a.assoc(s2.first).should equal(s2)
3939
end
40+
41+
it "calls to_ary on non-array elements" do
42+
s1 = [1, 2]
43+
s2 = ArraySpecs::ArrayConvertible.new(2, 3)
44+
a = [s1, s2]
45+
46+
s1.should_not_receive(:to_ary)
47+
a.assoc(s1.first).should equal(s1)
48+
49+
a.assoc(2).should == [2, 3]
50+
s2.called.should equal(:to_ary)
51+
end
4052
end

spec/ruby/core/array/rassoc_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,16 @@ def o.==(other); other == 'foobar'; end
3535

3636
[[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1]
3737
end
38+
39+
it "does not call to_ary on non-array elements" do
40+
s1 = [1, 2]
41+
s2 = ArraySpecs::ArrayConvertible.new(2, 3)
42+
a = [s1, s2]
43+
44+
s1.should_not_receive(:to_ary)
45+
a.rassoc(2).should equal(s1)
46+
47+
s2.should_not_receive(:to_ary)
48+
a.rassoc(3).should equal(nil)
49+
end
3850
end

spec/ruby/core/exception/full_message_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,49 @@
4646
full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n")
4747
end
4848

49+
describe "includes details about whether an exception was handled" do
50+
describe "RuntimeError" do
51+
it "should report as unhandled if message is empty" do
52+
err = RuntimeError.new("")
53+
54+
err.full_message.should =~ /unhandled exception/
55+
err.full_message(highlight: true).should =~ /unhandled exception/
56+
err.full_message(highlight: false).should =~ /unhandled exception/
57+
end
58+
59+
it "should not report as unhandled if the message is not empty" do
60+
err = RuntimeError.new("non-empty")
61+
62+
err.full_message.should !~ /unhandled exception/
63+
err.full_message(highlight: true).should !~ /unhandled exception/
64+
err.full_message(highlight: false).should !~ /unhandled exception/
65+
end
66+
67+
it "should not report as unhandled if the message is nil" do
68+
err = RuntimeError.new(nil)
69+
70+
err.full_message.should !~ /unhandled exception/
71+
err.full_message(highlight: true).should !~ /unhandled exception/
72+
err.full_message(highlight: false).should !~ /unhandled exception/
73+
end
74+
75+
it "should not report as unhandled if the message is not specified" do
76+
err = RuntimeError.new()
77+
78+
err.full_message.should !~ /unhandled exception/
79+
err.full_message(highlight: true).should !~ /unhandled exception/
80+
err.full_message(highlight: false).should !~ /unhandled exception/
81+
end
82+
end
83+
84+
describe "generic Error" do
85+
it "should not report as unhandled in any event" do
86+
StandardError.new("").full_message.should !~ /unhandled exception/
87+
StandardError.new("non-empty").full_message.should !~ /unhandled exception/
88+
end
89+
end
90+
end
91+
4992
it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
5093
begin
5194
line = __LINE__; raise "first line\nsecond line"

spec/ruby/core/file/new_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
File.should.exist?(@file)
101101
end
102102

103-
it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
103+
it "raises an Errno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
104104
-> { @fh = File.new(@file, File::CREAT|File::EXCL) }.should raise_error(Errno::EEXIST)
105105
end
106106

spec/ruby/core/file/open_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
end
355355
end
356356

357-
it "raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do
357+
it "raises an Errno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do
358358
-> {
359359
File.open(@file, File::CREAT|File::EXCL) do |f|
360360
f.puts("writing")
@@ -423,7 +423,7 @@
423423
}.should raise_error(IOError)
424424
end
425425

426-
it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
426+
it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
427427
-> {
428428
File.open(@file, File::RDONLY|File::TRUNC) do |f|
429429
f.puts("writing").should == nil
@@ -441,7 +441,7 @@
441441
}.should raise_error(Errno::EINVAL)
442442
end
443443

444-
it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
444+
it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
445445
-> {
446446
File.open(@file, File::RDONLY|File::TRUNC) do |f|
447447
f.puts("writing").should == nil

spec/ruby/core/kernel/Integer_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,21 @@
586586
Integer("777", obj).should == 0777
587587
end
588588

589+
# https://bugs.ruby-lang.org/issues/19349
590+
ruby_version_is ''...'3.3' do
591+
it "ignores the base if it is not an integer and does not respond to #to_i" do
592+
Integer("777", "8").should == 777
593+
end
594+
end
595+
596+
ruby_version_is '3.3' do
597+
it "raises a TypeError if it is not an integer and does not respond to #to_i" do
598+
-> {
599+
Integer("777", "8")
600+
}.should raise_error(TypeError, "no implicit conversion of String into Integer")
601+
end
602+
end
603+
589604
describe "when passed exception: false" do
590605
describe "and valid argument" do
591606
it "returns an Integer number" do

spec/ruby/core/method/parameters_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def one_key(a: 1); end
77
def one_keyrest(**a); end
88

99
def one_keyreq(a:); end
10+
def one_nokey(**nil); end
1011

1112
def one_splat_one_req(*a,b); end
1213
def one_splat_two_req(*a,b,c); end
@@ -15,6 +16,7 @@ def one_splat_one_req_with_block(*a,b,&blk); end
1516
def one_opt_with_stabby(a=-> b { true }); end
1617

1718
def one_unnamed_splat(*); end
19+
def one_unnamed_keyrest(**); end
1820

1921
def one_splat_one_block(*args, &block)
2022
local_is_not_parameter = {}
@@ -178,6 +180,11 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
178180
m.parameters.should == [[:keyreq,:a]]
179181
end
180182

183+
it "returns [[:nokey]] for a method with a single **nil parameter" do
184+
m = MethodSpecs::Methods.instance_method(:one_nokey)
185+
m.parameters.should == [[:nokey]]
186+
end
187+
181188
it "works with ->(){} as the value of an optional argument" do
182189
m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby)
183190
m.parameters.should == [[:opt,:a]]
@@ -225,17 +232,39 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
225232
end
226233

227234
ruby_version_is '3.2' do
228-
it "adds * rest arg for \"star\" argument" do
235+
it "adds rest arg with name * for \"star\" argument" do
229236
m = MethodSpecs::Methods.new
230237
m.method(:one_unnamed_splat).parameters.should == [[:rest, :*]]
231238
end
239+
240+
it "adds keyrest arg with ** as a name for \"double star\" argument" do
241+
m = MethodSpecs::Methods.new
242+
m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest, :**]]
243+
end
232244
end
233245

234246
ruby_version_is ''...'3.2' do
235247
it "adds nameless rest arg for \"star\" argument" do
236248
m = MethodSpecs::Methods.new
237249
m.method(:one_unnamed_splat).parameters.should == [[:rest]]
238250
end
251+
252+
it "adds nameless keyrest arg for \"double star\" argument" do
253+
m = MethodSpecs::Methods.new
254+
m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest]]
255+
end
256+
end
257+
258+
ruby_version_is '3.1' do
259+
it "adds block arg with name & for anonymous block argument" do
260+
object = Object.new
261+
262+
eval(<<~RUBY).should == [[:block, :&]]
263+
def object.foo(&)
264+
end
265+
object.method(:foo).parameters
266+
RUBY
267+
end
239268
end
240269

241270
it "returns the args and block for a splat and block argument" do

spec/ruby/core/proc/parameters_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
ruby_version_is "3.2" do
24-
it "sets the first element of each sub-Array to :req if argument would be required if a lambda if lambda keyword used" do
24+
it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do
2525
proc {|x| }.parameters(lambda: true).first.first.should == :req
2626
proc {|y,*x| }.parameters(lambda: true).first.first.should == :req
2727
end
@@ -91,19 +91,33 @@
9191
proc {|&block| }.parameters.first.last.should == :block
9292
end
9393

94-
it "ignores unnamed rest args" do
94+
it "ignores unnamed rest arguments" do
9595
-> x {}.parameters.should == [[:req, :x]]
9696
end
9797

9898
ruby_version_is '3.2' do
99-
it "adds * rest arg for \"star\" argument" do
100-
-> x, * {}.parameters.should == [[:req, :x], [:rest, :*]]
99+
it "adds rest arg with name * for \"star\" argument" do
100+
-> * {}.parameters.should == [[:rest, :*]]
101+
end
102+
103+
it "adds keyrest arg with ** as a name for \"double star\" argument" do
104+
-> ** {}.parameters.should == [[:keyrest, :**]]
101105
end
102106
end
103107

104108
ruby_version_is ''...'3.2' do
105109
it "adds nameless rest arg for \"star\" argument" do
106-
-> x, * {}.parameters.should == [[:req, :x], [:rest]]
110+
-> * {}.parameters.should == [[:rest]]
111+
end
112+
113+
it "adds nameless keyrest arg for \"double star\" argument" do
114+
-> ** {}.parameters.should == [[:keyrest]]
115+
end
116+
end
117+
118+
ruby_version_is '3.1' do
119+
it "adds block arg with name & for anonymous block argument" do
120+
eval('-> & {}.parameters').should == [[:block, :&]]
107121
end
108122
end
109123

spec/ruby/language/numbered_parameters_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@
8282
lambda { _9 }.arity.should == 9
8383
end
8484

85+
it "affects block parameters" do
86+
-> { _1 }.parameters.should == [[:req, :_1]]
87+
-> { _2 }.parameters.should == [[:req, :_1], [:req, :_2]]
88+
89+
proc { _1 }.parameters.should == [[:opt, :_1]]
90+
proc { _2 }.parameters.should == [[:opt, :_1], [:opt, :_2]]
91+
end
92+
93+
it "affects binding local variables" do
94+
-> { _1; binding.local_variables }.call("a").should == [:_1]
95+
-> { _2; binding.local_variables }.call("a", "b").should == [:_1, :_2]
96+
end
97+
8598
it "does not work in methods" do
8699
obj = Object.new
87100
def obj.foo; _1 end

spec/ruby/language/singleton_class_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,11 @@ def singleton_method; 1 end
307307
o.freeze
308308
klass.frozen?.should == true
309309
end
310+
311+
it "will be unfrozen if the frozen object is cloned with freeze set to false" do
312+
o = Object.new
313+
o.freeze
314+
o2 = o.clone(freeze: false)
315+
o2.singleton_class.frozen?.should == false
316+
end
310317
end

0 commit comments

Comments
 (0)