Example #1
0
 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))
Example #2
0
    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))
Example #3
0
 def should_check_unverified_collaborations(self):
     ''' check for unverified collaborations after start_collaborating '''
     spec = Spec(MockSpec())
     spec.when(spec.foo(), spec.start_collaborating())
     spec.then(spec.verify())
     msg = 'should be collaborating with unnamed_mock.foo()'
     spec.should_raise(UnmetSpecification(msg))
     
     spec = Spec(MockSpec())
     spec.when(spec.foo(), spec.start_collaborating(), spec.foo())
     spec.then(spec.verify())
     spec.should_not_raise(UnmetSpecification)
Example #4
0
    def should_check_unverified_collaborations(self):
        ''' check for unverified collaborations after start_collaborating '''
        spec = Spec(MockSpec())
        spec.when(spec.foo(), spec.start_collaborating())
        spec.then(spec.verify())
        msg = 'should be collaborating with unnamed_mock.foo()'
        spec.should_raise(UnmetSpecification(msg))

        spec = Spec(MockSpec())
        spec.when(spec.foo(), spec.start_collaborating(), spec.foo())
        spec.then(spec.verify())
        spec.should_not_raise(UnmetSpecification)
Example #5
0
    def should_have_meaningful_msg(self):
        ''' Raise should produce meaningful UnmetSpecification messages'''
        spec = Spec(Raise(IndexError))
        msg = "should raise IndexError"
        spec.describe_constraint().should_be(msg)
        spec.verify(dont_raise_index_error)
        spec.should_raise(UnmetSpecification(msg))

        spec = Spec(Raise(IndexError('with some message')))
        msg = "should raise IndexError('with some message',)"
        spec.describe_constraint().should_be(msg)
        unmet_msg = msg + ", not IndexError('with message',)"
        unmet_specification = UnmetSpecification(unmet_msg)
        spec.verify(raise_index_error).should_raise(unmet_specification)
Example #6
0
    def should_have_meaningful_msg(self):
        ''' Raise should produce meaningful UnmetSpecification messages'''
        spec = Spec(Raise(IndexError))
        msg = "should raise IndexError"
        spec.describe_constraint().should_be(msg)
        spec.verify(dont_raise_index_error)
        spec.should_raise(UnmetSpecification(msg))

        spec = Spec(Raise(IndexError('with some message')))
        msg = "should raise IndexError('with some message',)"
        spec.describe_constraint().should_be(msg)
        unmet_msg = msg + ", not IndexError('with message',)"
        unmet_specification = UnmetSpecification(unmet_msg)
        spec.verify(raise_index_error).should_raise(unmet_specification)