Skip to content

Commit 8916178

Browse files
committed
1 parent e16a0c2 commit 8916178

31 files changed

+271
-71
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/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/io/read_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,32 @@
299299
@io.read(10, buf).should == nil
300300

301301
buf.should == ''
302+
303+
buf = 'non-empty string'
304+
305+
@io.read(nil, buf).should == ""
306+
307+
buf.should == ''
308+
309+
buf = 'non-empty string'
310+
311+
@io.read(0, buf).should == ""
312+
313+
buf.should == ''
314+
end
315+
316+
it "raise FrozenError if the output buffer is frozen" do
317+
@io.read
318+
-> { @io.read(0, 'frozen-string'.freeze) }.should raise_error(FrozenError)
319+
-> { @io.read(1, 'frozen-string'.freeze) }.should raise_error(FrozenError)
320+
-> { @io.read(nil, 'frozen-string'.freeze) }.should raise_error(FrozenError)
321+
end
322+
323+
ruby_bug "", ""..."3.3" do
324+
it "raise FrozenError if the output buffer is frozen (2)" do
325+
@io.read
326+
-> { @io.read(1, ''.freeze) }.should raise_error(FrozenError)
327+
end
302328
end
303329

304330
it "consumes zero bytes when reading zero bytes" do

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/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

spec/ruby/library/English/English_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@
130130
$LAST_MATCH_INFO.should == $~
131131
end
132132

133-
it "aliases $IGNORECASE to $=" do
134-
$VERBOSE, verbose = nil, $VERBOSE
135-
begin
136-
$IGNORECASE.should_not be_nil
137-
$IGNORECASE.should == $=
138-
ensure
139-
$VERBOSE = verbose
133+
ruby_version_is ""..."3.3" do
134+
it "aliases $IGNORECASE to $=" do
135+
$VERBOSE, verbose = nil, $VERBOSE
136+
begin
137+
$IGNORECASE.should_not be_nil
138+
$IGNORECASE.should == $=
139+
ensure
140+
$VERBOSE = verbose
141+
end
140142
end
141143
end
142144

spec/ruby/library/date/iso8601_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
d.should == Date.civil(-4712, 1, 1)
2323
end
2424

25+
it "raises a Date::Error if the argument is a invalid Date" do
26+
-> {
27+
Date.iso8601('invalid')
28+
}.should raise_error(Date::Error, "invalid date")
29+
end
30+
31+
it "raises a Date::Error when passed a nil" do
32+
-> {
33+
Date.iso8601(nil)
34+
}.should raise_error(Date::Error, "invalid date")
35+
end
36+
2537
it "raises a TypeError when passed an Object" do
2638
-> { Date.iso8601(Object.new) }.should raise_error(TypeError)
2739
end
@@ -32,4 +44,13 @@
3244
h = Date._iso8601('invalid')
3345
h.should == {}
3446
end
47+
48+
it "returns an empty hash if the argument is nil" do
49+
h = Date._iso8601(nil)
50+
h.should == {}
51+
end
52+
53+
it "raises a TypeError when passed an Object" do
54+
-> { Date._iso8601(Object.new) }.should raise_error(TypeError)
55+
end
3556
end

spec/ruby/library/date/shared/parse.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
d.day.should == 23
1414
end
1515

16-
it "can parse a 'mmm DD YYYY' string into a Date object" do
16+
it "can parse a 'DD mmm YYYY' string into a Date object" do
1717
d = Date.parse("23#{@sep}feb#{@sep}2008")
1818
d.year.should == 2008
1919
d.month.should == 2
@@ -42,7 +42,7 @@
4242
d.should == Date.civil(2005, 11, 5)
4343
end
4444

45-
it "can parse a year, day and month name into a Date object" do
45+
it "can parse a day, month name and year into a Date object" do
4646
d = Date.parse("5th#{@sep}november#{@sep}2005")
4747
d.should == Date.civil(2005, 11, 5)
4848
end

0 commit comments

Comments
 (0)