Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Honestly, I couldn't tell you the best way to do that in MSpec. But I've experienced a similar class explosion problem with MSpec when using it in similar circumstances. I don't know if you have ever tried RSpec. In RSpec contexts and specifications are built up within the confines of executable code. What that means is you can create a data structure, iterate on it, and create several contexts and specs using one block of code. This becomes especially handy when you are trying to specify how something based in mathematics behaves (prime factors,tic tac toe, chess, etc...). A single pattern of behavior can be specified across each member of a set of given and expected values.</p> <p>This example is written in NSpec, a context/spec framework for C# modeled after RSpec. I purposefully left a failing spec. I just went down this kata far enough to find a place to use iteration. The failing spec forces you to resolve the shortcomings of the naive implementation.</p> <p>Here's another example of prime factor kata: <a href="http://nspec.org/#dolambda" rel="nofollow">http://nspec.org/#dolambda</a></p> <p>Output:</p> <pre><code>describe Knight when moving 2 back and 1 left when a knight at D4 is moved to B3 knight position should be B3 when a knight at C4 is moved to A3 knight position should be A3 - FAILED - String lengths are both 2. Strings differ at index 0., Expected: "A3", But was: "B3", -----------^ **** FAILURES **** describe Knight. when moving 2 back and 1 left. when a knight at C4 is moved to A3. knight position should be A3. String lengths are both 2. Strings differ at index 0., Expected: "A3", But was: "B3", -----------^ at ChessSpecs.describe_Knight.&lt;&gt;c__DisplayClass5.&lt;when_moving_2_back_and_1_left&gt;b__4() in c:\Users\matt\Documents\Visual Studio 2010\Projects\ChessSpecs\ChessSpecs\describe_Knight.cs:line 23 2 Examples, 1 Failed, 0 Pending </code></pre> <p>Code:</p> <pre><code>using System.Collections.Generic; using NSpec; class describe_Knight : nspec { void when_moving_2_back_and_1_left() { new Each&lt;string,string&gt; { {"D4", "B3"}, {"C4", "A3"}, }.Do( (start, moveTo) =&gt; { context["when a knight at {0} is moved to {1}".With(start,moveTo)] = () =&gt; { before = () =&gt; { knight = new Knight(start); knight.Move(moveTo); }; it["knight position should be {0}".With(moveTo)] = () =&gt; knight.Position.should_be(moveTo); }; }); } Knight knight; } class Knight { public Knight(string position) { Position = position; } public void Move(string position) { Position = "B3"; } public string Position { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload