Skip to content

Commit 2c16e93

Browse files
committed
1 parent cbb97d5 commit 2c16e93

21 files changed

+340
-47
lines changed

spec/ruby/core/array/drop_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
23

34
describe "Array#drop" do
45
it "removes the specified number of elements from the start of the array" do
@@ -48,4 +49,16 @@
4849

4950
-> { [1, 2].drop(obj) }.should raise_error(TypeError)
5051
end
52+
53+
ruby_version_is ''...'3.0' do
54+
it 'returns a subclass instance for Array subclasses' do
55+
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(ArraySpecs::MyArray)
56+
end
57+
end
58+
59+
ruby_version_is '3.0' do
60+
it 'returns a Array instance for Array subclasses' do
61+
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should be_an_instance_of(Array)
62+
end
63+
end
5164
end

spec/ruby/core/array/drop_while_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
23

34
describe "Array#drop_while" do
45
it "removes elements from the start of the array while the block evaluates to true" do
@@ -12,4 +13,16 @@
1213
it "removes elements from the start of the array until the block returns false" do
1314
[1, 2, 3, false, 5].drop_while { |n| n }.should == [false, 5]
1415
end
16+
17+
ruby_version_is ''...'3.0' do
18+
it 'returns a subclass instance for Array subclasses' do
19+
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(ArraySpecs::MyArray)
20+
end
21+
end
22+
23+
ruby_version_is '3.0' do
24+
it 'returns a Array instance for Array subclasses' do
25+
ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should be_an_instance_of(Array)
26+
end
27+
end
1528
end

spec/ruby/core/array/slice_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,64 @@ def to.to_int() -2 end
185185
a.should == [3, 4]
186186
end
187187
end
188+
189+
describe "with a subclass of Array" do
190+
before :each do
191+
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
192+
end
193+
194+
ruby_version_is ''...'3.0' do
195+
it "returns a subclass instance with [n, m]" do
196+
@array.slice!(0, 2).should be_an_instance_of(ArraySpecs::MyArray)
197+
end
198+
199+
it "returns a subclass instance with [-n, m]" do
200+
@array.slice!(-3, 2).should be_an_instance_of(ArraySpecs::MyArray)
201+
end
202+
203+
it "returns a subclass instance with [n..m]" do
204+
@array.slice!(1..3).should be_an_instance_of(ArraySpecs::MyArray)
205+
end
206+
207+
it "returns a subclass instance with [n...m]" do
208+
@array.slice!(1...3).should be_an_instance_of(ArraySpecs::MyArray)
209+
end
210+
211+
it "returns a subclass instance with [-n..-m]" do
212+
@array.slice!(-3..-1).should be_an_instance_of(ArraySpecs::MyArray)
213+
end
214+
215+
it "returns a subclass instance with [-n...-m]" do
216+
@array.slice!(-3...-1).should be_an_instance_of(ArraySpecs::MyArray)
217+
end
218+
end
219+
220+
ruby_version_is '3.0' do
221+
it "returns a Array instance with [n, m]" do
222+
@array.slice!(0, 2).should be_an_instance_of(Array)
223+
end
224+
225+
it "returns a Array instance with [-n, m]" do
226+
@array.slice!(-3, 2).should be_an_instance_of(Array)
227+
end
228+
229+
it "returns a Array instance with [n..m]" do
230+
@array.slice!(1..3).should be_an_instance_of(Array)
231+
end
232+
233+
it "returns a Array instance with [n...m]" do
234+
@array.slice!(1...3).should be_an_instance_of(Array)
235+
end
236+
237+
it "returns a Array instance with [-n..-m]" do
238+
@array.slice!(-3..-1).should be_an_instance_of(Array)
239+
end
240+
241+
it "returns a Array instance with [-n...-m]" do
242+
@array.slice!(-3...-1).should be_an_instance_of(Array)
243+
end
244+
end
245+
end
188246
end
189247

190248
describe "Array#slice" do

spec/ruby/core/array/take_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
23

34
describe "Array#take" do
45
it "returns the first specified number of elements" do
@@ -24,4 +25,16 @@
2425
it "raises an ArgumentError when the argument is negative" do
2526
->{ [1].take(-3) }.should raise_error(ArgumentError)
2627
end
28+
29+
ruby_version_is ''...'3.0' do
30+
it 'returns a subclass instance for Array subclasses' do
31+
ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(ArraySpecs::MyArray)
32+
end
33+
end
34+
35+
ruby_version_is '3.0' do
36+
it 'returns a Array instance for Array subclasses' do
37+
ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should be_an_instance_of(Array)
38+
end
39+
end
2740
end

spec/ruby/core/array/take_while_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative '../../spec_helper'
2+
require_relative 'fixtures/classes'
23

34
describe "Array#take_while" do
45
it "returns all elements until the block returns false" do
@@ -12,4 +13,16 @@
1213
it "returns all elements until the block returns false" do
1314
[1, 2, false, 4].take_while{ |element| element }.should == [1, 2]
1415
end
16+
17+
ruby_version_is ''...'3.0' do
18+
it 'returns a subclass instance for Array subclasses' do
19+
ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(ArraySpecs::MyArray)
20+
end
21+
end
22+
23+
ruby_version_is '3.0' do
24+
it 'returns a Array instance for Array subclasses' do
25+
ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should be_an_instance_of(Array)
26+
end
27+
end
1528
end

spec/ruby/core/dir/children_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,18 @@
100100
a.should == %w|.dotfile.ext directory|
101101
end
102102

103-
it "accepts an options Hash" do
103+
it "accepts an encoding keyword for the encoding of the entries" do
104104
@dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8")
105-
a = @dir.children.sort
106-
a.should == %w|.dotfile.ext directory|
105+
dirs = @dir.to_a.sort
106+
dirs.each { |d| d.encoding.should == Encoding::UTF_8 }
107+
end
108+
109+
ruby_version_is ""..."2.7" do
110+
it "accepts nil options" do
111+
@dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested", nil)
112+
dirs = @dir.to_a.sort
113+
dirs.each { |d| d.encoding.should == Encoding.find("filesystem") }
114+
end
107115
end
108116

109117
it "returns children encoded with the filesystem encoding by default" do

spec/ruby/core/dir/each_child_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
DirSpecs.delete_mock_dirs
1111
end
1212

13+
it "accepts an encoding keyword for the encoding of the entries" do
14+
dirs = Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
15+
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
16+
end
17+
18+
ruby_version_is ""..."2.7" do
19+
it "accepts nil options" do
20+
dirs = Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
21+
dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
22+
end
23+
end
24+
1325
it "yields all names in an existing directory to the provided block" do
1426
a, b = [], []
1527

spec/ruby/core/dir/entries_spec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@
3535
Dir.entries(p)
3636
end
3737

38-
it "accepts an options Hash" do
39-
a = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").sort
40-
a.should == %w|. .. .dotfile.ext directory|
38+
it "accepts an encoding keyword for the encoding of the entries" do
39+
dirs = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
40+
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
41+
end
42+
43+
ruby_version_is ""..."2.7" do
44+
it "accepts nil options" do
45+
dirs = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
46+
dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
47+
end
4148
end
4249

4350
it "returns entries encoded with the filesystem encoding by default" do

spec/ruby/core/dir/foreach_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
Dir.foreach(DirSpecs.mock_dir).to_a.sort.should == DirSpecs.expected_paths
4040
end
4141

42+
it "accepts an encoding keyword for the encoding of the entries" do
43+
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
44+
dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
45+
end
46+
47+
ruby_version_is ""..."2.7" do
48+
it "accepts nil options" do
49+
dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", nil).to_a.sort
50+
dirs.each {|dir| dir.encoding.should == Encoding.find("filesystem")}
51+
end
52+
end
53+
4254
describe "when no block is given" do
4355
it "returns an Enumerator" do
4456
Dir.foreach(DirSpecs.mock_dir).should be_an_instance_of(Enumerator)

spec/ruby/core/env/except_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require_relative 'spec_helper'
2+
require_relative 'shared/to_hash'
3+
4+
ruby_version_is "3.0" do
5+
describe "ENV.except" do
6+
before do
7+
@orig_hash = ENV.to_hash
8+
end
9+
10+
after do
11+
ENV.replace @orig_hash
12+
end
13+
14+
# Testing the method without arguments is covered via
15+
it_behaves_like :env_to_hash, :except
16+
17+
it "returns a hash without the requested subset" do
18+
ENV.clear
19+
20+
ENV['one'] = '1'
21+
ENV['two'] = '2'
22+
ENV['three'] = '3'
23+
24+
ENV.except('one', 'three').should == { 'two' => '2' }
25+
end
26+
27+
it "ignores keys not present in the original hash" do
28+
ENV.clear
29+
30+
ENV['one'] = '1'
31+
ENV['two'] = '2'
32+
33+
ENV.except('one', 'three').should == { 'two' => '2' }
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)