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 6c64ad2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/rspec/support/source/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ def location
@location ||= args.find { |arg| arg.is_a?(Location) }
end

def each(&block)
def each
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 6c64ad2

Please sign in to comment.