freerange / mocha

A mocking and stubbing library for Ruby

Home Page:https://mocha.jamesmead.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unstub in the `then` clause

nhorton opened this issue · comments

First off, I have to say again how much i appreciate the work on Mocha and your follow-up on issues - its amazing.

I have a scenario where there is either a feature request or an approach I am missing.

I am trying to write a test for something that deletes a set of ActiveRecord records. I need to simulate one of them having a problem and the delete failing.

The ideal way of doing it would be:

MyClass.any_instance.stubs(:destroy!).raises(PG:ForeignKeyViolation).then(unstub)

Because that would actually let most of the destroys get through, but one would get caught and a raise would happen.

Thanks again!