Skip to content

Commit

Permalink
Use loop-based DFS to resolve rspec#341 (SystemStackError)
Browse files Browse the repository at this point in the history
  • Loading branch information
craigjbass committed Jan 27, 2018
1 parent 2f9091b commit dcb4c12
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rspec/support/source/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ def location
def each(&block)
return to_enum(__method__) unless block_given?

yield self
outstanding_nodes = []
outstanding_nodes << self
while outstanding_nodes.length > 0
current_node = outstanding_nodes.pop
current_node.children.each do |node|
outstanding_nodes.unshift(node)
end

children.each do |child|
child.each(&block)
yield current_node
end
end

Expand Down

0 comments on commit dcb4c12

Please sign in to comment.