0

I'm using NBehave to write out my stories and using Rhino Mocks to mock out dependencies of the System(s) Under Test.

However I'm having a problem resetting expected behaviour in my mock dependencies when moving from one scenario to the next.

I only want to assert that the save method on my repository was called in two scenarios:

dependancyRepository.AssertWasCalled( ear =>
    ear.Save(
        Arg<IDependancy>.Is.Equal(dependency)
    )
)

But this is being called in each scenario and fails in my second scenario because the Rhino Mocks expects it be called just once. I don't want to be forced to use an explicit expections but it kinda looks like I'll have too.

There are a few examples out there of NBehave with Rhino Mocks but I can't one that has multiple scenarios. And there are a few with NBehave and multiple Scenarios but no mocks.

Anybody else run into this issue?

Cheers

  • I'm not sure I completely understand your scenario. If you call AssertWasCalled, it will throw if the method wasn't invoked. That's the purpose of this method, and if you don't want that, couldn't you just not call it? Maybe there are some expectations that are being violated, but from your example I can't see how your dependancyRepository variable was created and configured, so it's hard to tell what is wrong. Perhaps you could share that code as well? – Mark Seemann Jun 26 '09 at 15:13

2 Answers2

0

If you don't want want to assert that .Save(...) was called in each scenario, then don't set up that expectation for each scenario, set it up only for the scenarios where you expect it to be called.

If this doesn't answer your question, please clarify your question with more information; it's unclear what you're trying to do.

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
0

Make the AssertWasCalled call during your Then clause of the relevant scenario, and not in any others.

John Rayner
  • 3,485
  • 21
  • 13