Add specs for Set mutation during iteration

This commit is contained in:
Jean Boussier 2025-05-13 22:30:50 +02:00
parent 1ee4b43a56
commit b6698114e6
2 changed files with 16 additions and 0 deletions

View File

@ -23,4 +23,12 @@ describe "Set#add?" do
@set.add?("cat")
@set.add?("cat").should be_nil
end
it "raises RuntimeError when called during iteration" do
set = Set[:a, :b, :c, :d, :e, :f]
set.each do |_m|
-> { set << 1 }.should raise_error(RuntimeError, /iteration/)
end
set.should == Set[:a, :b, :c, :d, :e, :f]
end
end

View File

@ -10,6 +10,14 @@ describe "Set#replace" do
@set.should == Set[1, 2, 3]
end
it "raises RuntimeError when called during iteration" do
set = Set[:a, :b, :c, :d, :e, :f]
set.each do |_m|
-> { set.replace(Set[1, 2, 3]) }.should raise_error(RuntimeError, /iteration/)
end
set.should == Set[:a, :b, :c, :d, :e, :f]
end
it "accepts any enumerable as other" do
@set.replace([1, 2, 3]).should == Set[1, 2, 3]
end