Skip to content

Commit 1f5d7b5

Browse files
committed
Fix Enumerable#to_set spec on 4.1
1 parent 1f8654d commit 1f5d7b5

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

core/range/to_set_spec.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
end
1313

1414
ruby_version_is "4.0" do
15-
it "instantiates an object of provided as the first argument set class" do
16-
set = nil
17-
proc{set = (1..3).to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)
18-
set.should be_kind_of(EnumerableSpecs::SetSubclass)
19-
set.to_a.sort.should == [1, 2, 3]
20-
end
21-
2215
it "raises a RangeError if the range is infinite" do
2316
-> { (1..).to_set }.should raise_error(RangeError, "cannot convert endless range to a set")
2417
-> { (1...).to_set }.should raise_error(RangeError, "cannot convert endless range to a set")
@@ -33,6 +26,25 @@
3326
end
3427
end
3528

29+
ruby_version_is "4.0"..."4.1" do
30+
it "instantiates an object of provided as the first argument set class and warns" do
31+
set = nil
32+
proc {
33+
set = (1..3).to_set(EnumerableSpecs::SetSubclass)
34+
}.should complain(/Enumerable#to_set/)
35+
set.should be_kind_of(EnumerableSpecs::SetSubclass)
36+
set.to_a.sort.should == [1, 2, 3]
37+
end
38+
end
39+
40+
ruby_version_is "4.1" do
41+
it "does not accept any positional argument" do
42+
-> {
43+
(1..3).to_set(EnumerableSpecs::SetSubclass)
44+
}.should raise_error(ArgumentError, 'wrong number of arguments (given 1, expected 0)')
45+
end
46+
end
47+
3648
it "does not need explicit `require 'set'`" do
3749
output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
3850
puts (1..3).to_set.to_a.inspect

0 commit comments

Comments
 (0)