has207/flexmock — Issue #61: A never() expectation should fail immediately if called
Author: nickesk
Created: 2011-11-03 20:34:52+00:00
State: open

Right now, it looks as if flexmock waits until tearDown to verify that a `never` expectation is met. However, since one usually doesn't specify a return value when declaring a `never`, other parts of the class under test are likely to raise an error (usually a NoneType AttributeError), masking the mock failure.

Since argument validations fail upon execution, it should be simple to have a `never` fail when called. In fact, this should probably be generalized to fail immediately whenever an `at_most(N)` expectation fails (since `never` is equivalent to `at_most(0)`).

Here's a contrived example:

```python
class TestMe(object):

def example(self):
if self.some_condition():
retval = some_module.do_some_work()
return retval.exit_status()
else:
return

class TestMeTest(unittest.TestCase):

def testExample(self):
flexmock(some_module)
some_module.should_receive('do_some_work').never
TestMe().example()

```

This test errors out with an AttributeError (specifically 'NoneType' object has no attribute 'exit_status'). It's much more useful to see a flexmock expectation failed here instead, especially when doing TDD.