1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!perl
use strict;
use warnings;
use Test::More;
use Test::BDD::Cucumber::Parser;
use Test::BDD::Cucumber::Executor;
use Test::BDD::Cucumber::Harness::Data;
my $feature = Test::BDD::Cucumber::Parser->parse_string(
<<HEREDOC
Feature: Test Feature
Conditions of satisfaction
Background:
Given a passing step called 'background-foo'
Given a background step that sometimes passes
Scenario:
Given a passing step called 'bar'
Given a passing step called 'baz'
Scenario:
Given a passing step called 'bar'
Given a passing step called '<name>'
Examples:
| name |
| bat |
| ban |
| fan |
HEREDOC
);
my $pass_until = 2;
my $executor = Test::BDD::Cucumber::Executor->new();
$executor->add_steps(
[ Given => qr/a passing step called '(.+)'/, sub { 1; } ],
[ Given => 'a background step that sometimes passes', sub {
ok( ( $pass_until && $pass_until-- ), "Still passes" );
}],
);
my $harness = Test::BDD::Cucumber::Harness::Data->new();
$executor->execute( $feature, $harness );
my @scenarios = @{ $harness->features->[0]->{'scenarios'} };
# We should have four scenarios. The first one, and then the three
# implied by the outline.
is( @scenarios, 4, "Five scenarios found" );
# Of this, the first two should have passed, the third failed,
# and the fourth skipped...
my $scenario_status = sub { $harness->scenario_status( $scenarios[shift()] )->result };
is( $scenario_status->(0), 'passing', "Scenario 1 passes" );
is( $scenario_status->(1), 'passing', "Scenario 2 passes" );
is( $scenario_status->(2), 'failing', "Scenario 3 fails" );
is( $scenario_status->(3), 'pending', "Scenario 4 marked pending" );
# Third scenario should have four steps. Two from the background,
# and two from definition
my @steps = @{
$harness->features->[0]
->{'scenarios'}->[2]
->{'steps'}
};
is( @steps, 4, "Four steps found" );
# The step pattern we should see in Scenario 3 is
# Pass/Fail/Skip/Skip
my $step_status = sub { $harness->step_status( $steps[shift()])->result };
is( $step_status->(0), 'passing', "Step 1 passes" );
is( $step_status->(1), 'failing', "Step 2 fails" );
is( $step_status->(2), 'pending', "Step 3 pending" );
is( $step_status->(3), 'pending', "Step 4 pending" );
done_testing();
|