Exemplo n.º 1
0
def test_call_method_can_raise_an_exception():
    '''Substitute: How to raise exceptions'''

    # System under Test
    substitute = Substitute()

    # Act: Configure
    substitute.method.raises(Apology)

    # Act: Run
    substitute.method()
Exemplo n.º 2
0
def test_call_method_on_substitute():
    '''Substitute: How to verify that a method was called'''

    # System under Test
    substitute = Substitute()

    # Act: Run
    substitute.method()

    # Assert
    assert_true(substitute.method.was_called)
    assert_false(substitute.other_method.was_called)
Exemplo n.º 3
0
def test_call_intercepts_argument_tuples():
    '''Substitute: How to intercept method arguments'''

    # System under Test
    substitute = Substitute()

    # Act: Run
    substitute.method(0, [])

    # Assert
    assert_equal(substitute.method.args, (0, []))
    assert_true(substitute.method.was_called_with(0, []))
Exemplo n.º 4
0
def test_call_intercepts_several_arguments():
    '''Substitute: When a method was called several times, all arguments are stored'''

    # System under Test
    substitute = Substitute()

    # Act: Run
    substitute.method('hello')
    substitute.method('bye')

    # Assert
    assert_true(substitute.method.was_called_with('hello'))
    assert_true(substitute.method.was_called_with('bye'))
Exemplo n.º 5
0
def test_calls_are_counted():
    '''Substitute: How to verify that a method was called several times'''

    # System under Test
    substitute = Substitute()

    # Arrange
    substitute.method()
    assert_true(substitute.method.was_called)
    assert_false(substitute.method.was_called_times(2))

    # Act: Run
    substitute.method()

    # Assert
    assert_true(substitute.method.was_called)
    assert_true(substitute.method.was_called_times(2))
Exemplo n.º 6
0
def test_call_method_returns_none():
    '''Substitute: How to call a method on a substitute'''

    # System under Test
    substitute = Substitute()

    # Act: Run
    data = substitute.method()

    # Assert
    assert_equal(data, None)
Exemplo n.º 7
0
def test_call_intercepts_many_arguments():
    '''Substitute: When a call had many arguments, they are returned as a tuple'''

    # System under Test
    substitute = Substitute()

    # Act: Run
    data = substitute.method('hello', 1, 2, 3)

    # Assert
    assert_equal(substitute.method.args, ('hello', 1, 2, 3))
Exemplo n.º 8
0
def test_call_intercepts_single_argument():
    '''Substitute: How to intercept the arguments of a call'''

    # System under Test
    substitute = Substitute()

    # Act: Run
    data = substitute.method('hello')

    # Assert
    assert_equal(substitute.method.args, 'hello')
Exemplo n.º 9
0
def test_call_method_can_return_data():
    '''Substitute: How to provide data from a method'''

    # System under Test
    substitute = Substitute()

    # Act: Configure
    substitute.method.returns(1)

    # Act: Run
    data = substitute.method()

    # Assert
    assert_equal(data, 1)
Exemplo n.º 10
0
def test_call_intercepts_asserts_arguments():
    '''Substitute: How to verify that a method was called with specific arguments'''

    # System under Test
    substitute = Substitute()

    # Act: Configure
    substitute.method.returns(1)

    # Act: Run
    data = substitute.method('hello')

    # Assert
    assert_true(substitute.method.was_called_with('hello'))
    assert_false(substitute.method.was_called_with('bye'))