コード例 #1
0
    def test_prompt_renders_all_questions(self):
        question1 = dbx.Stub()
        question1.name = 'foo'
        result1 = object()

        question2 = dbx.Stub()
        question2.name = 'bar'
        result2 = object()

        result = object()
        with dbx.Spy() as render:
            render.reset()
            render.render(question1, {}).returns(result1)
            render.render(question2, {'foo': result1}).returns(result2)

        result = prompt([question1, question2], render=render)

        self.assertEquals({'foo': result1, 'bar': result2}, result)
        dbx.assert_that(
            render.render,
            dbx.called().with_args(question1, dbx.ANY_ARG))

        dbx.assert_that(
            render.render,
            dbx.called().with_args(question2,
                                   dbx.ANY_ARG))
コード例 #2
0
    def test_called(self):
        spy = doublex.Spy()

        expected = '''
Expected: these calls:
          Spy.expected(ANY_ARG)
     but: calls that actually ocurred were:
          No one'''

        self.assert_with_message(spy.expected, doublex.called(), expected)
コード例 #3
0
    def test__hamcrest_not__called_with_matcher(self):
        spy = doublex.Spy()
        spy.unexpected(2)

        self.assert_with_message(
            spy.unexpected,
            is_not(doublex.called().with_args(greater_than(1))), '''
Expected: not these calls:
          Spy.unexpected(a value greater than <1>)
     but: was ''')
コード例 #4
0
    def test_called_with_matcher(self):
        spy = doublex.Spy()

        self.assert_with_message(
            spy.unexpected,
            doublex.called().with_args(greater_than(1)), '''
Expected: these calls:
          Spy.unexpected(a value greater than <1>)
     but: calls that actually ocurred were:
          No one''')
コード例 #5
0
    def test_hamcrest_not_called(self):
        spy = doublex.Spy()
        spy.foo(1)
        spy.foo(2)
        spy.unexpected(5)

        self.assert_with_message(
            spy.unexpected, is_not(doublex.called()), '''
Expected: not these calls:
          Spy.unexpected(ANY_ARG)
     but: was ''')
コード例 #6
0
    def test_expected_set(self):
        spy = doublex.Spy(ObjCollaborator)

        expected_message = '''
Expected: these calls:
          set ObjCollaborator.prop to ANYTHING
     but: calls that actually ocurred were:
          No one
'''

        self.assert_with_message(spy, doublex.property_set('prop'),
                                 expected_message)
コード例 #7
0
    def test_hamcrest_not_called_with(self):
        spy = doublex.Spy()

        spy.foo(1)
        spy.foo(2)
        spy.unexpected(2)

        self.assert_with_message(
            spy.unexpected, is_not(doublex.called().with_args(2)), '''
Expected: not these calls:
          Spy.unexpected(2)
     but: but was ''')
コード例 #8
0
    def test_unexpected_set(self):
        expected_message = '''
Expected: none of these calls:
          set ObjCollaborator.prop to ANYTHING
     but: calls that actually ocurred were:
          set ObjCollaborator.prop to unexpected
'''

        spy = doublex.Spy(ObjCollaborator)
        spy.prop = 'unexpected'

        self.assert_with_message(
            spy, doublex.never(doublex.property_set('prop')),
            expected_message)
コード例 #9
0
    def test_unexpected_get(self):
        expected_message = '''
Expected: none of these calls:
          get ObjCollaborator.prop
     but: calls that actually ocurred were:
          get ObjCollaborator.prop
'''

        spy = doublex.Spy(ObjCollaborator)
        spy.prop

        self.assert_with_message(
            spy, doublex.never(doublex.property_got('prop')),
            expected_message)
コード例 #10
0
    def test_called_with(self):
        spy = doublex.Spy()

        spy.foo(1)
        spy.foo(2)

        self.assert_with_message(
            spy.expected, doublex.called().with_args(3),
            '''
Expected: these calls:
          Spy.expected(3)
     but: calls that actually ocurred were:
          Spy.foo(1)
          Spy.foo(2)''')
コード例 #11
0
    def test_called_times_matcher(self):
        spy = doublex.Spy()

        spy.foo(1)
        spy.foo(2)

        self.assert_with_message(
            spy.foo, doublex.called().times(greater_than(3)),
            '''
Expected: these calls:
          Spy.foo(ANY_ARG) -- times: a value greater than <3>
     but: calls that actually ocurred were:
          Spy.foo(1)
          Spy.foo(2)''')
コード例 #12
0
    def test_called_times_int(self):
        spy = doublex.Spy()

        spy.foo(1)
        spy.foo(2)

        self.assert_with_message(
            spy.foo, doublex.called().times(1),
            '''
Expected: these calls:
          Spy.foo(ANY_ARG) -- times: 1
     but: calls that actually ocurred were:
          Spy.foo(1)
          Spy.foo(2)''')
コード例 #13
0
    def test_nerver_called(self):
        spy = doublex.Spy()

        spy.foo(1)
        spy.foo(2)
        spy.unexpected(5)

        self.assert_with_message(
            spy.unexpected, doublex.never(doublex.called()), '''
Expected: none of these calls:
          Spy.unexpected(ANY_ARG)
     but: calls that actually ocurred were:
          Spy.foo(1)
          Spy.foo(2)
          Spy.unexpected(5)''')
コード例 #14
0
# -*- coding: utf-8 -*-

import doublex
from expects import expect, contain
from expects.testing import failure

from doublex_expects import *

with describe('have_been_called'):
    with before.each:
        self.method = doublex.Spy().method

    with it('passes if method called'):
        self.method()

        expect(self.method).to(have_been_called)

    with it('passes if method called twice'):
        self.method()
        self.method()

        expect(self.method).to(have_been_called)

    with it('fails if method not called'):
        with failure("calls were:\n          No one"):
            expect(self.method).to(have_been_called)

    with context('when negated'):
        with it('passes if not called'):
            expect(self.method).not_to(have_been_called)