views:

173

answers:

2

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

A: 

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 Himango
A: 

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

John Rayner