from __future__ import absolute_import

import sys

from nose.plugins.base import Plugin

from doubles.lifecycle import setup, verify, teardown
from doubles.exceptions import MockExpectationError


class NoseIntegration(Plugin):
    name = 'doubles'

    def beforeTest(self, test):
        setup()

    def afterTest(self, test):
        teardown()

    def prepareTestCase(self, test):
        def wrapped(result):
            test.test.run()
            if result.failures or result.errors:
                return
            try:
                verify()
            except MockExpectationError:
                result.addFailure(test.test,  sys.exc_info())
        return wrapped

@@ -136,17 +136,32 @@
 teardown
+, current_space
 %0A
-
 from dou
@@ -331,32 +331,64 @@
 st(self, test):%0A
+        if current_space():%0A    
         teardown
@@ -390,16 +390,16 @@
 rdown()%0A
-
 %0A    def
@@ -574,16 +574,56 @@
    try:%0A
+                if current_space():%0A    
         

Make nose integration a bit safer