mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Add specs for Set mutation during iteration
This commit is contained in:
parent
1ee4b43a56
commit
b6698114e6
2 changed files with 16 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue