Commits

Kumar McMillan committed b0e9aca

out of order assertions are now made early and often

Comments (0)

Files changed (3)

docs/using-fudge.rst

 
     >>> fudge.clear_calls()
     >>> session.set_count(5)
-    >>> session.get_count()
-    0
-    >>> session.get_count()
-    5
-    >>> fudge.verify()
     Traceback (most recent call last):
     ...
     AssertionError: Call #1 was fake:session.set_count(5); Expected: #1 fake:session.get_count()[0], #2 fake:session.set_count(5), #3 fake:session.get_count()[1]

fudge/__init__.py

                 exp.assert_called()
                 exp.assert_times_called()
             for fake, call_order in self.get_expected_call_order().items():
-                call_order.assert_order_met()
+                call_order.assert_order_met(finalize=True)
         finally:
             self.clear_calls()
         
         self.actual_times_called += 1
         if self.call_order:
             self.call_order.add_actual_call(self)
+            self.call_order.assert_order_met(finalize=False)
         
         if self.exception_to_raise is not None:
             raise self.exception_to_raise
     def add_actual_call(self, call):
         self._actual_calls.append(call)
     
-    def assert_order_met(self):
+    def assert_order_met(self, finalize=False):
         error = None
         if len(self._actual_calls) == 0:
             error = "Not enough calls were made"
         else:
             for i,call in enumerate(self._call_order):
                 if len(self._actual_calls) < i+1:
+                    if not finalize:
+                        # we're not done asserting calls so 
+                        # forget about not having enough calls
+                        continue
+                        
                     calls_made = len(self._actual_calls)
                     if calls_made == 1:
                         error = "Only 1 call was made"
                     else:
                         error = "Only %s calls were made" % calls_made
                     break
+                    
                 ac_call = self._actual_calls[i]
                 if ac_call is not call:
                     error = "Call #%s was %r" % (i+1, ac_call)
             >>> import fudge
             >>> db = fudge.Fake('db').remember_order().expects('insert').expects('update')
             >>> db.update()
-            >>> db.insert()
-            >>> fudge.verify()
             Traceback (most recent call last):
             ...
             AssertionError: Call #1 was fake:db.update(); Expected: #1 fake:db.insert(), #2 fake:db.update()

fudge/tests/test_fudge.py

     
     @raises(AssertionError)
     def test_not_enough_calls(self):
+        # need to drop down a level to bypass expected calls:
         r = Registry()
         fake = Fake()
         call_order = ExpectedCallOrder(fake)
         r.remember_expected_call_order(call_order)
         
-        exp = ExpectedCall(fake, "callMe")
+        exp = ExpectedCall(fake, "callMe", call_order=call_order)
         call_order.add_expected_call(exp)
         
         r.verify()
+        
+    @raises(AssertionError)
+    def test_only_one_call(self):
+        # need to drop down a level to bypass expected calls:
+        r = Registry()
+        fake = Fake()
+        call_order = ExpectedCallOrder(fake)
+        r.remember_expected_call_order(call_order)
+        
+        exp = ExpectedCall(fake, "one", call_order=call_order)
+        call_order.add_expected_call(exp)
+        exp() # call this
+        
+        exp = ExpectedCall(fake, "two", call_order=call_order)
+        call_order.add_expected_call(exp)
+        
+        r.verify()
+        
+    def test_incremental_order_assertion_ok(self):
+        # need to drop down a level to bypass expected calls:
+        fake = Fake()
+        call_order = ExpectedCallOrder(fake)
+        
+        exp = ExpectedCall(fake, "one", call_order=call_order)
+        call_order.add_expected_call(exp)
+        exp() # call this
+        
+        exp = ExpectedCall(fake, "two", call_order=call_order)
+        call_order.add_expected_call(exp)
+        
+        # two() not called but assertion is not finalized:
+        call_order.assert_order_met(finalize=False)
     
     def test_multiple_return_values_are_ignored(self):
         db = Fake("db")\