JBehave’s Story Runner runs through scenarios as follows:
Given a context
When an event happens
Then this outcome occurs.
So you’d think it would visit these in the order “context, event, outcome”.
Unfortunately, the mocks all have to be set up before the event – so what you actually get is “context, outcome (setUp), event, outcome (verify)”.
What’s more, when you come to replace the mocks with real code, expectations in setUp become checks in verify,
mockHellboundGui.expects("setVisible") before the event becomes
assertTrue(swingHellboundGui.isVisible()) after the event.
The expectations are a kind of verification anyway. Wouldn’t it be great if you could set them up in verify, instead of setUp? If you could just create mocks in setUp (or even in the event, perhaps, where you use them), then add all the expectations at the end, after the methods have been called but before you call
mockFoo.verify()? You wouldn’t do
expects("setVisible"), you’d do
This would also help with another problem I have; where the (real) Hellbound game factory creates a game, but I can’t expect the game to be passed to the arguments of any of my mocks as I didn’t have hold of it in setUp.
Unfortunately all the current mock schemes insist on you expecting a method before it gets called, or they fall over. What a pain.