1 module tests.given_when_then; 2 3 import unit_threaded; 4 import cucumber.keywords; 5 import cucumber.feature; 6 7 private string[] funcCalls; 8 9 @Given(r"^A situation$") 10 void given() { 11 funcCalls ~= "Given"; 12 } 13 14 @When(r"^I do this") 15 void when() { 16 funcCalls ~= "When"; 17 } 18 19 @Then(r"^This happens") 20 void then() { 21 funcCalls ~= "Then"; 22 } 23 24 @When(r"I do a failing step$") 25 void failingStep() { 26 funcCalls ~= "failingStep"; 27 throw new Exception("Exception: step failed"); 28 } 29 30 void testGivenUndefinedWithNoMapping() { 31 funcCalls = []; 32 const results = runFeature!__MODULE__(["Non matching string"]); 33 shouldEqual(results.numScenarios, 1); 34 shouldEqual(results.numPassing, 0); 35 shouldEqual(results.numFailing, 0); 36 shouldEqual(results.numPending, 0); 37 shouldEqual(results.numUndefined, 1); 38 shouldEqual(results.toString(), "1 scenario (1 undefined)"); 39 shouldEqual(funcCalls, []); 40 } 41 42 void testGivenWhenThen() { 43 funcCalls = []; 44 const results = runFeature!__MODULE__(["Feature: A feature", " Scenario: A Scenario:", 45 " Given A situation", 46 " When I do this", 47 " Then This happens"]); 48 shouldEqual(results.numScenarios, 1); 49 shouldEqual(results.numPassing, 1); 50 shouldEqual(results.numFailing, 0); 51 shouldEqual(results.numPending, 0); 52 shouldEqual(results.numUndefined, 0); 53 shouldEqual(results.toString(), "1 scenario (1 passed)"); 54 shouldEqual(funcCalls, ["Given", "When", "Then"]); 55 }