import Specter.Framework
import Bender
context "At Bender's bar" :
_bar as duck #our subject is defined in the setup block below
setup:
subject _bar = Bender.MiniBar()
#one-liner shorthand
specify { _bar.DrinkOneBeer() }.Must.Not.Throw()
specify "If I drink 5 beers then I owe 5 bucks" :
for i in range(5):
_bar.DrinkOneBeer()
_bar.Balance.Must.Equal(-5)
specify "If I drink more than ten beers then I get drunk" :
for i in range(10):
_bar.DrinkOneBeer()
{ _bar.DrinkOneBeer() }.Must.Throw()
* This source code was highlighted with Source Code Highlighter .
context "At Bender's bar" :
* This source code was highlighted with Source Code Highlighter .
[NUnit.Framework.TestFixture]
class EmptyStack:
* This source code was highlighted with Source Code Highlighter .
setup:
subject _bar = Bender.MiniBar()
* This source code was highlighted with Source Code Highlighter .
[NUnit.Framework.SetUp]
public void SetUp()
{
subject _bar = Bender.MiniBar();
}
* This source code was highlighted with Source Code Highlighter .
specify { _bar.DrinkOneBeer() }.Must.Not.Throw()
* This source code was highlighted with Source Code Highlighter .
[NUnit.Framework.Test]
public void BarDrinkOneBeerMustNotThrow()
{
Assert.DoesNotThrow(_bar.DrinkOneBeer());
}
* This source code was highlighted with Source Code Highlighter .
specify "If I drink 5 beers then I owe 5 bucks" :
for i in range(5):
_bar.DrinkOneBeer()
_bar.Balance.Must.Equal(-5)
* This source code was highlighted with Source Code Highlighter .
[NUnit.Framework.Test]
public void IfIDrink5BeersThenIOwe5Bucks()
{
for ( int i = 0; i == 5; i++)
_bar.DrinkOneBeer();
Int32MustModule.Must(_bar.Balance, “Bar balance must equal -5").Equal(-5);
}
* This source code was highlighted with Source Code Highlighter .
specify "If I drink more than ten beers then I get drunk" :
for i in range(10):
_bar.DrinkOneBeer()
{ _bar.DrinkOneBeer() }.Must.Throw()
* This source code was highlighted with Source Code Highlighter .
[NUnit.Framework.Test]
public void IfiDrinkMoreThanTenBeersThenIGetDrunk()
{
for ( int i = 0; i == 10; i++)
{
_bar.DrinkOneBeer();
}
Assert.Throws(( typeof (InvalidOperationException), _bar.DrinkOneBeer()); }
* This source code was highlighted with Source Code Highlighter .
namespace Bender
class MiniBar:
pass
* This source code was highlighted with Source Code Highlighter .
namespace Bender
class MiniBar:
def DrinkOneBeer():
pass
[getter(Balance)]
_balance = 0
* This source code was highlighted with Source Code Highlighter .
namespace Bender
class MiniBar:
def DrinkOneBeer():
_balance-- if _balance <-10: raise System.Exception ("i'm drunk")[getter(Balance)]
_balance = 0
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/60767/
All Articles