freerange/mocha — pull request #168 by tdg5 (2013-12-01 16:46:32+00:00)
Title: Rescue SystemStackError during mocha_inspect

If an expectation is set on #inspect or a method that inspect calls and an unexpected invocation occurs, a SystemStackError occurs.

This happens because the unexpected invocation causes mocha_inspect to be called which calls inspect which causes another unexpected invocation, which again causes mocha_inspect to be called, on and on until eventually a stack overflow occurs.

This diff changes mocha_inspect to fall back to using the default string representation of an object if a SystemStackError occurs.

It might be preferable to raise a different kind of error after rescuing the SystemStackError, I'm not sure. A different error might be preferable because rescuing the SystemStackError in this way causes an expectation error like the following:
```
unexpected invocation: #.inspect()
unsatisfied expectations:
- expected exactly once, invoked 1390 times: #.inspect(any_parameters)
```
The invocation count of 1390 could be confusing when there's probably only one extraneous invocation that's causing the problem. I chose the rescue route because although 1390 may be confusing, it is still clear that some kind of unexpected invocation is occurring which is much more useful than the SystemStackError and useless backtrace that greeted me when I ran into this issue.

If you think raising a different error is a better approach or there is anything else here that needs fixing, let me know and I'll update the pull request.