'Using Minitest, how do I stub calls to several different class methods

How do I stub calls to several different class methods when using Minitest.

For example, I want to test this method:

  def index
    categories = CategoryAnalyzer.for_user(current_user)
    @root_categories = categories.select { |c| c.parent_id.nil? }
    @max_depth = CategoryAnalyzer.max_depth(categories)
    @children_by_id = CategoryAnalyzer.children_by_id(categories)
  end 

Notice that it calls three separate class methods on CategoryAnalyzer. How do I stub all three methods (for_user, max_depth, and children_by_id?

("Stub" might not be the correct word. I only need one stub at a time (e.g., to verify that max_depth is called with the correct parameter); but, in order to set that test up, I do need to specify what for_user should return.)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source