Skip to content

Instantly share code, notes, and snippets.

@nestorsalceda
Created October 4, 2012 18:28
Show Gist options
  • Save nestorsalceda/3835471 to your computer and use it in GitHub Desktop.
Save nestorsalceda/3835471 to your computer and use it in GitHub Desktop.
python + rspec?
class CalculatorDescription(Description):
def before(self):
self.calc = Calculator()
def it_adds_two_numbers(self):
expect(self.calc.add(2,4)).to_be(6)
@description('division')
def it_divides_two_numbers(self):
expect(test.calc.divide(8, 4)).to_be(2)
@description('division')
def it_doesnt_divide_by_zero(self):
with expect.raises(ZeroDivisionError):
self.calc.divide(8, 0)
def it_multiplies_two_numbers(self):
expect(test.calc.divide(2, 3)).to_be(6)
-----
with describe(Calculator):
def before(self):
self.calc = Calculator()
def it_adds_two_numbers(self):
expect(self.calc.add(2,4)).to_be(6)
with describe('division'):
def it_divides_two_numbers(self):
expect(test.calc.divide(8, 4)).to_be(2)
def it_doesnt_divide_by_zero(self):
with expect.raises(ZeroDivisionError):
self.calc.divide(8, 0)
def it_multiplies_two_numbers(self):
expect(test.calc.divide(2, 3)).to_be(6)
-----
with describe(Calculator) as it:
@it.before
def before(test):
test.calc = Calculator()
with it("adds two numbers") as test:
test.assertEqual(test.calc.add(2, 4), 6)
with it("divides two numbers") as test:
test.assertEqual(test.calc.divide(8, 4), 2)
with it("doesn't divide by zero") as test:
with test.assertRaises(ZeroDivisionError):
test.calc.divide(8, 0)
with it("multiplies two numbers") as test:
test.assertEqual(test.calc.multiply(2, 3), 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment