def should_verify_specified_collaborations(self): ''' after start_collaborating, collaborations should be verified ''' spec = Spec(MockSpec(name='a')) spec.when(spec.start_collaborating()) spec.then(spec.foo()) msg = 'should not be collaborating with a.foo()' spec.should_raise(UnmetSpecification(msg)) spec = Spec(MockSpec(name='b')) spec.when(spec.foo(), spec.start_collaborating()) spec.then(spec.bar()) msg = 'should be collaborating with b.foo(), not b.bar()' spec.should_raise(UnmetSpecification(msg)) spec = Spec(MockSpec(name='c')) spec.when(spec.foo(), spec.bar(), spec.start_collaborating()) spec.then(spec.foo()).should_not_raise(UnmetSpecification) msg = 'should be collaborating with c.bar(), not c.baz()' spec.then(spec.baz()).should_raise(UnmetSpecification(msg)) mock = MockSpec(name='d') mock.foo().times(2).will_return('camelot') spec = Spec(mock) spec.when(spec.start_collaborating()) spec.then(spec.foo()).should_not_raise(UnmetSpecification) spec.then(spec.foo()).should_not_raise(UnmetSpecification) msg = 'should not be collaborating with d.foo()' spec.then(spec.foo()).should_raise(UnmetSpecification(msg))
def using_mock_call(): ''' collaboration specification should use MockCall ''' spec = Spec(MockSpec()) spec.foo().should_be(Type(MockCall)) spec.bar(12).should_be(Type(MockCall)) spec.baz(keyword='named argument').should_be(Type(MockCall))