Specter is the infrastructure for composing object-behavioral specifications for .NET. It provides opportunities to ensure development, guided by system behavior ( BDD ), requiring developers to write an executable specification for objects before writing the objects themselves. Technically, this is no different from the development of test tools ( TDD ), although differences in the form of writing remove the psychological barrier to writing “tests” for code that does not yet exist. There are many projects for various platforms that implement this idea (for example, RSpec for Ruby , NSpec for .NET . Read more about the environments here ).import Specter.Frameworkimport Bendercontext "At Bender's bar" :_bar as duck #our subject is defined in the setup block belowsetup:subject _bar = Bender.MiniBar()#one-liner shorthandspecify { _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 .
![minibar-result1 [1] minibar-result1[1]](https://habrastorage.org/getpro/habr/post_images/c94/e70/b12/c94e70b12801420e9585b6e79395436d.jpg)
namespace Benderclass MiniBar:pass* This source code was highlighted with Source Code Highlighter .
namespace Benderclass MiniBar:def DrinkOneBeer():pass[getter(Balance)]_balance = 0* This source code was highlighted with Source Code Highlighter .
![minibar-result2 [1] minibar-result2[1]](https://habrastorage.org/getpro/habr/post_images/4ec/70b/2b4/4ec70b2b4d9f33109524b8d45bd6f7fa.jpg)
namespace Benderclass 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 .
![minibar-result3 [1] minibar-result3[1]](https://habrastorage.org/getpro/habr/post_images/6b1/641/c38/6b1641c38396f27dd2722e94b1f06a2a.jpg)
Source: https://habr.com/ru/post/60767/
All Articles