1

I want to verify that a number of functions were called in a specific order, but one of the functions gets called N times:

verifyOrder {
    myMockObject.func1()
    (exactly = 10) myMockObject.func2()
    myMockObject.func3()
}

How do I specify the "exactly = 10" above?

k314159
  • 5,051
  • 10
  • 32

1 Answers1

0

That is not possible. Your best option would be verifySequence, which verifies that the calls happened in a specified sequence.

verifySequence {
   myMockObject.func1()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func2()
   myMockObject.func3()
}

It is not pretty, but to my knowledge, you have no better alternative.

João Dias
  • 16,277
  • 6
  • 33
  • 45
  • 1
    Thanks. And for future readers wondering what is the difference between verifyOrder and verifySequence, I've just researched it and I think verifyOrder allows other calls to happen in between those being verified, while verifySequence does not. – k314159 Oct 05 '21 at 22:13
  • Exactly. `verifySequence` is an exact match while `verifyOrder` just checks that those calls respect the given order, but other calls may be omitted from `verifyOrder`. Good point @k314159 ;) – João Dias Oct 05 '21 at 22:18
  • Thanks for confirming. The official docs are a bit vague on that distinction. – k314159 Oct 05 '21 at 22:24