--[[
	Add a new describe node with the given method as a callback. Generates or
	reuses all the describe nodes along the path.
]]

function TestPlan:addRoot(path, method, instance)
	local curNode = self
	for i = #path, 1, -1 do
		local nextNode = nil

		for _, child in ipairs(curNode.children) do
			if child.phrase == path[i] then
				nextNode = child
				break
			end
		end

		if nextNode == nil then
			local filePath = getFilePathFromInstance(instance)
			nextNode = curNode:addChild(path[i], TestEnum.NodeType.Describe, nil, filePath)
		end

		curNode = nextNode
	end

	curNode.isRoot = true
	curNode.instance = instance
	curNode.callback = method
	curNode:expand()
end
