def test_verifies_a_method_was_called_with_the_right_arguments(self): expectation = ShouldReceiveExpectation(self.stub, Args.make(1)) self.stub(1) expectation.verify() new_stub = Stub('new_stub') new_stub.set_default_response('response') expectation = ShouldReceiveExpectation(new_stub, Args.make(1)) new_stub('wrong', 'args') try: expectation.verify() except AssertionError, e: self.assertEqual("Expected new_stub(1) to be called but it wasn't.", str(e))
def test_verifies_a_stub_was_not_called_with_specific_arguments(self): self.expectation.set_call_args(Args.make(1)) self.stub('some other args') self.expectation.verify() self.stub(1) with self.assertRaises(AssertionError): self.expectation.verify()
def test_verifies_mock_expectations(self): stub = Stub('stub') stub.set_default_response('response') passing_expectation = ShouldReceiveExpectation(stub, AnyArgs) failing_expectation = ShouldReceiveExpectation(stub, Args.make('some args')) self.test_environment.add_mock_expectation(passing_expectation) self.test_environment.add_mock_expectation(failing_expectation) stub('random args') try: self.test_environment.verify_expectations() except AssertionError, e: self.assertEqual("Expected stub('some args') to be called but it " "wasn't.", str(e))
def test_can_set_args_after_object_is_created(self): expectation = ShouldReceiveExpectation(self.stub, Args.make(1)) expectation.set_call_args(AnyArgs) self.stub('any args') expectation.verify()
def test_has_a_repr_that_looks_like_call_arguments(self): args = Args.make(1, 2, kw1='a string', kw2=3) self.assertEqual("(1, 2, kw1='a string', kw2=3)", repr(args))