Skip to content

Instantly share code, notes, and snippets.

@vbabiy
Created June 3, 2011 00:32
Show Gist options
  • Save vbabiy/1005637 to your computer and use it in GitHub Desktop.
Save vbabiy/1005637 to your computer and use it in GitHub Desktop.
import unittest
from chai import Chai
class Walrus(object):
def __init__(self):
self.energy = 0
def receive_gift(self, gift):
if gift.is_editable():
self.energy += gift.digest().energy
class LifeEvent(object):
def __init__(self, energy=0):
self.energy = energy
class WalrusTestCase(Chai):
def setUp(self):
super(WalrusTestCase, self).setUp()
self.subject = Walrus()
def test_walrus_gains_enegery_by_eating_food(self):
cheese = self.mock()
self.expect(cheese.is_editable).returns(True)
self.expect(cheese.digest).returns(LifeEvent(energy=100))
self.subject.receive_gift(cheese)
self.assert_equals(self.subject.energy, 100)
def test_walrus_ignores_non_ediable_things(self):
shoe = self.mock()
self.expect(shoe.is_editable).returns(False)
self.subject.receive_gift(shoe)
self.assert_equals(self.subject.energy, 0)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment