For those who don't know the kata. There are a number of predefined specifications written in the Gherkin DSL based around the movement of 2 chess pieces on a chessboard.
This is the feature we were implementing.
Feature: Boundaries of the board.We've completed most of the steps on each of the scenarios using a location class implementing
In order to obey the rules of Chess
As a player
I want to be prevented from entering moves outside the boundary of the board.
Scenario: Pawn at top.
Given I have a White Pawn at A8
And I have a Black Knight at A1
When I move the Pawn to A9
Then I should be warned of an illegal move message
Scenario: Knight heads off board
Given I have a Black Knight at G8
And I have a White Pawn at A1
And I move the Pawn to A2
When I move the Knight to I7
Then I should be warned of an illegal move message
public interface ILocation
{
void MoveTo(string location);
}
Each time we touched a class we've covered it with mspec tests.
[Subject(typeof(Location))]
public class When_creating_a_location_with_an_invalid_position
{
Because of = () =>; exception = Catch.Exception(() =>; new Location("Z22"));
Behaves_like<AnInvalidLocation>; its_in_the_wrong_location;
protected static Exception exception;
}
[Subject(typeof(Location))]
public class When_moving_a_piece_to_invalid_location
{
Establish that = () =>; location = new Location("A1");
Because of = () =>; exception = Catch.Exception( ()=>; location.MoveTo("X2"));
Behaves_like<AnInvalidLocation> an_invalid_move;
protected static Exception exception;
static ILocation location;
}
I've DRYed out (a little) the invalid move behaviour in my Location.Now that I've come to implement my final step, "Then I should be warned of an illegal move message".
I suddenly need to implement the invalid move behaviour. (Even though the WHEN is where the invalid move occurs I don't need to write the behaviour yet).
So this is where the emergent design has lead me to. If I am to follow the YAGNI or LRM principles I don't want do anything thing more than display a message. But If I change the behaviour of my location classes' MoveTo method to return a message, then the good design principles that my class level specifications has lead me too are at odds with the demands of the specification passing.
I am trying not to introduce another class to handle game messaging but by not doing so I undo my hard work at the class level. Is this the last responsible moment?