spec/async/node_spec.rb in async-1.25.0 vs spec/async/node_spec.rb in async-1.25.1

- old
+ new

@@ -33,18 +33,18 @@ it "should break nested tree" do child.parent = nil expect(child.parent).to be_nil - expect(subject.children).to be_empty + expect(subject.children).to be_nil end it "can consume bottom to top" do child.consume expect(child.parent).to be_nil - expect(subject.children).to be_empty + expect(subject.children).to be_nil end end describe '#print_hierarchy' do let(:buffer) {StringIO.new} @@ -62,20 +62,38 @@ expect(lines[1]).to be =~ /\t#<Async::Node:0x\h+>\n/ end end describe '#consume' do - let(:middle) {Async::Node.new(subject)} - let(:bottom) {Async::Node.new(middle)} - it "can't consume middle node" do + middle = Async::Node.new(subject) + bottom = Async::Node.new(middle) + expect(bottom.parent).to be middle middle.consume expect(bottom.parent).to be middle end + + it "can consume node while enumerating children" do + 3.times do + Async::Node.new(subject) + end + + children = subject.children.each.to_a + expect(subject.children.size).to be 3 + + enumerated = [] + + subject.children.each do |child| + child.consume + enumerated << child + end + + expect(enumerated).to be == children + end end describe '#annotate' do let(:annotation) {'reticulating splines'} @@ -127,13 +145,13 @@ it 'can move transient sibling to parent' do # This example represents a server task (middle) which has a single task listening on incoming connections (child2), and a transient task which is monitoring those connections/some shared resource (child1). We look at what happens when the server listener finishes. # subject -> middle -> child1 (transient) # -> child2 - middle = Async::Node.new(subject) - child1 = Async::Node.new(middle, transient: true) - child2 = Async::Node.new(middle) + middle = Async::Node.new(subject, annotation: "middle") + child1 = Async::Node.new(middle, transient: true, annotation: "child1") + child2 = Async::Node.new(middle, annotation: "child2") allow(child1).to receive(:finished?).and_return(false) middle.consume @@ -167,9 +185,9 @@ # subject -> middle (transient) expect(child.parent).to be_nil expect(middle.parent).to be subject expect(subject.children).to include(middle) - expect(middle.children).to be_empty + expect(middle.children).to be_nil end end end