regexps for steps should not include leading 'Given|Then|...'

This commit is contained in:
Emmanuel Briot 2014-02-10 11:56:30 +01:00
parent 162bfb4237
commit 79e951e504
3 changed files with 25 additions and 5 deletions

View File

@ -23,6 +23,7 @@
with Ada.Exceptions; use Ada.Exceptions;
with BDD.Steps; use BDD.Steps;
with GNATCOLL.Utils; use GNATCOLL.Utils;
package body BDD.Runner is
@ -150,6 +151,9 @@ package body BDD.Runner is
Step : not null access Step_Record'Class)
is
Execute : constant Boolean := Scenario.Status = Status_Passed;
Text : constant String := Step.Text;
First : Integer := Text'First;
begin
-- Run the step, or at least check whether it is defined.
if Execute then
@ -158,9 +162,20 @@ package body BDD.Runner is
Step.Set_Status (Status_Skipped);
end if;
-- Skip the leading 'Given|Then|...' keywords, which are irrelevant
-- for the purpose of the match
while First <= Text'Last
and then not Is_Whitespace (Text (First))
loop
First := First + 1;
end loop;
Skip_Blanks (Text, First);
begin
-- Will set status to undefined if necessary
BDD.Steps.Run_Step (Step, Execute => Execute);
BDD.Steps.Run_Step
(Step, Text (First .. Text'Last), Execute => Execute);
-- if Step.Status = Status_Undefined then
-- -- ??? Could run some predefined steps here
-- null;

View File

@ -26,11 +26,11 @@ with GNAT.Regpat; use GNAT.Regpat;
package body BDD.Steps is
Re_1 : constant Pattern_Matcher := Compile
("^Given a user named '(.*)'$");
("^a user named '(.*)'$");
Re_2 : constant Pattern_Matcher := Compile
("^Given I am sitting at my desk$");
("^I am sitting at my desk$");
Re_3 : constant Pattern_Matcher := Compile
("^Then I should create great software$");
("^I should create great software$");
procedure Do_Step_1 (Name : String);
procedure Do_Step_2;
@ -70,9 +70,9 @@ package body BDD.Steps is
procedure Run_Step
(Step : not null access BDD.Features.Step_Record'Class;
Text : String;
Execute : Boolean)
is
Text : constant String := Step.Text;
Matches : Match_Array (0 .. 10);
begin
Match (Re_1, Text, Matches);

View File

@ -30,10 +30,15 @@ package BDD.Steps is
procedure Run_Step
(Step : not null access BDD.Features.Step_Record'Class;
Text : String;
Execute : Boolean);
-- Run a step, and sets its status.
--
-- If Execute is False, then we only check whether the step is known, but
-- it is not run. No exception is raised in this mode.
--
-- Text must be Step.Text, minus the leading 'Given|Then|...' words.
--
-- This procedure is expected to raise exceptions when a test fails.
end BDD.Steps;