|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +from expects import expect, equal, raise_error |
| 4 | +from mamba import description, context, it |
| 5 | + |
| 6 | +from fizzbuzz import fizzbuzz |
| 7 | + |
| 8 | +with description('Playing FizzBuzz') as self: |
| 9 | + with context('when passed the value 3'): |
| 10 | + with it('says "Fizz"'): |
| 11 | + expect(fizzbuzz(3)).to(equal('Fizz')) |
| 12 | + |
| 13 | + with context('when passed a multiple of 3'): |
| 14 | + with it('says "Fizz"'): |
| 15 | + expect(fizzbuzz(9)).to(equal('Fizz')) |
| 16 | + |
| 17 | + with context('when passed the value 5'): |
| 18 | + with it('says "Buzz"'): |
| 19 | + expect(fizzbuzz(5)).to(equal('Buzz')) |
| 20 | + |
| 21 | + with context('when passed a multiple of 5'): |
| 22 | + with it('says "Buzz"'): |
| 23 | + expect(fizzbuzz(20)).to(equal('Buzz')) |
| 24 | + |
| 25 | + with context('when passed a multiple of 3 and 5'): |
| 26 | + with it('says "FizzBuzz"'): |
| 27 | + expect(fizzbuzz(15)).to(equal('FizzBuzz')) |
| 28 | + |
| 29 | + with context('when passed a value divisible by neither 3 nor 5'): |
| 30 | + with it('says the value back unchanged'): |
| 31 | + expect(fizzbuzz(1)).to(equal(1)) |
| 32 | + expect(fizzbuzz(2)).to(equal(2)) |
| 33 | + |
| 34 | + with context('when passed a none whole integer value'): |
| 35 | + with it('screams and raises a ValueError'): |
| 36 | + # Use lambda to overcome deficiency in expects library |
| 37 | + expect(lambda: fizzbuzz(3.14)).to(raise_error(ValueError)) |
| 38 | + |
| 39 | + with context('when pass a none numeric value'): |
| 40 | + with it('screams and raises a ValueError'): |
| 41 | + # Use lambda to overcome deficiency in expects library |
| 42 | + expect(lambda: fizzbuzz('fred')).to(raise_error(ValueError)) |
0 commit comments