1. 3
  1.  

  2. 1

    To ride my personal hobby horse, I think the main cause is mutable objects that have side effects - in the example given, building a database query by mutation. You have to have a stub return a stub because you’re mutating, and then you evaluate that object to return the actual data your code cares about.

    I really agree nested stubbing shouts for refactoring, and I like the simple approach of putting it behind a method. Neat to see many paths to the same place (in another example I could imagine getitng here through the Law of Demeter).