| 1 | 11 | ▶ | use v5.14; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 11 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | package Test::BDD::Cucumber::Harness::Data 0.87; | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Test::BDD::Cucumber::Harness::Data - Builds up an internal data representation of test passes / failures | ||
| 9 | |||
| 10 | =head1 VERSION | ||
| 11 | |||
| 12 | version 0.87 | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | A L<Test::BDD::Cucumber::Harness> subclass which collates test data | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | 11 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 11 | ▶ | use Types::Standard qw( HashRef ArrayRef ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 11 | ▶ | use Test::More; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 11 | ▶ | use Test::BDD::Cucumber::Model::Result; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | |||
| 25 | 11 | extends 'Test::BDD::Cucumber::Harness'; | |
| 26 | |||
| 27 | =head1 ATTRIBUTES | ||
| 28 | |||
| 29 | =head2 features | ||
| 30 | |||
| 31 | An array-ref in which we store all the features executed, and completed. Until | ||
| 32 | C<feature_done> is called, it won't be in here. | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | 39 | ▶ | has 'features' => ( is => 'rw', isa => ArrayRef, default => sub { [] } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 37 | |||
| 38 | =head2 current_feature | ||
| 39 | |||
| 40 | =head2 current_scenario | ||
| 41 | |||
| 42 | =head2 current_step | ||
| 43 | |||
| 44 | The current feature/step/scenario for which we've had the starting method, but | ||
| 45 | not the C<_done> method. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | has 'current_feature' => | ||
| 50 | 31 | ▶ | ( is => 'rw', isa => HashRef, default => sub { {} } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 51 | has 'current_scenario' => | ||
| 52 | 31 | ▶ | ( is => 'rw', isa => HashRef, default => sub { {} } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 53 | 39 | ▶ | has 'current_step' => ( is => 'rw', isa => HashRef, default => sub { {} } ); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 54 | |||
| 55 | =head2 feature | ||
| 56 | |||
| 57 | =head2 feature_done | ||
| 58 | |||
| 59 | Feature hashref looks like: | ||
| 60 | |||
| 61 | { | ||
| 62 | object => Test::BDD::Cucumber::Model::Feature object | ||
| 63 | scenarios => [] | ||
| 64 | } | ||
| 65 | |||
| 66 | =cut | ||
| 67 | |||
| 68 | # We will keep track of where we are each time... | ||
| 69 | 13 | ▶ | sub feature { |
|
Subroutine
feature: called CC=1 SCAR=0.0
Pod
documented
| |||
| 70 | 13 | my ( $self, $feature ) = @_; | |
| 71 | 13 | my $feature_ref = { | |
| 72 | object => $feature, | ||
| 73 | scenarios => [] | ||
| 74 | }; | ||
| 75 | 13 | $self->current_feature($feature_ref); | |
| 76 | } | ||
| 77 | |||
| 78 | 21 | ▶ | sub feature_done { |
|
Subroutine
feature_done: called CC=1 SCAR=0.0
Pod
documented
| |||
| 79 | 21 | my $self = shift; | |
| 80 | 21 | push( @{ $self->features }, $self->current_feature ); | |
| 81 | 21 | $self->current_feature( {} ); | |
| 82 | } | ||
| 83 | |||
| 84 | =head2 scenario | ||
| 85 | |||
| 86 | =head2 scenario_done | ||
| 87 | |||
| 88 | Scenario hashref looks like: | ||
| 89 | |||
| 90 | { | ||
| 91 | object => Test::BDD::Cucumber::Model::Scenario object | ||
| 92 | dataset => Data hash the scenario was invoked with | ||
| 93 | steps => [], | ||
| 94 | } | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | 26 | ▶ | sub scenario { |
|
Subroutine
scenario: called CC=1 SCAR=0.0
Pod
documented
| |||
| 99 | 26 | my ( $self, $scenario, $dataset ) = @_; | |
| 100 | 26 | my $scenario_ref = { | |
| 101 | object => $scenario, | ||
| 102 | dataset => $dataset, | ||
| 103 | steps => [], | ||
| 104 | }; | ||
| 105 | 26 | $self->current_scenario($scenario_ref); | |
| 106 | } | ||
| 107 | |||
| 108 | 26 | ▶ | sub scenario_done { |
|
Subroutine
scenario_done: called CC=1 SCAR=0.0
Pod
documented
| |||
| 109 | 26 | my $self = shift; | |
| 110 | 26 | push( @{ $self->current_feature->{'scenarios'} }, $self->current_scenario ); | |
| 111 | 26 | $self->current_scenario( {} ); | |
| 112 | } | ||
| 113 | |||
| 114 | =head2 step | ||
| 115 | |||
| 116 | =head2 step_done | ||
| 117 | |||
| 118 | Step hashref looks like: | ||
| 119 | |||
| 120 | { | ||
| 121 | context => Test::BDD::Cucumber::StepContext object | ||
| 122 | result => Test::BDD::Cucumber::Model::Result object (after step_done) | ||
| 123 | } | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | 60 | ▶ | sub step { |
|
Subroutine
step: called CC=1 SCAR=0.0
Pod
documented
| |||
| 128 | 60 | my ( $self, $step_context ) = @_; | |
| 129 | 60 | my $step_ref = { context => $step_context }; | |
| 130 | 60 | $self->current_step($step_ref); | |
| 131 | } | ||
| 132 | |||
| 133 | 60 | ▶ | sub step_done { |
|
Subroutine
step_done: called CC=1 SCAR=0.0
Pod
documented
| |||
| 134 | 60 | my ( $self, $context, $result, $highlights ) = @_; | |
| 135 | |||
| 136 | 60 | $self->current_step->{'result'} = $result; | |
| 137 | 60 | $self->current_step->{'highlights'} = $highlights; | |
| 138 | 60 | push( @{ $self->current_scenario->{'steps'} }, $self->current_step ); | |
| 139 | 60 | $self->current_step( {} ); | |
| 140 | } | ||
| 141 | |||
| 142 | =head2 feature_status | ||
| 143 | |||
| 144 | =head2 scenario_status | ||
| 145 | |||
| 146 | =head2 step_status | ||
| 147 | |||
| 148 | Accepting one of the data-hashes above, returns a | ||
| 149 | L<Test::BDD::Cucumber::Model::Result> object representing it. If it's a Feature | ||
| 150 | or a Scenario, then it returns one representing all the child objects. | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | # Status methods | ||
| 155 | 2 | ▶ | sub feature_status { |
|
Subroutine
feature_status: called CC=1 SCAR=0.0
Pod
documented
| |||
| 156 | 2 | my ( $self, $feature ) = @_; | |
| 157 | return Test::BDD::Cucumber::Model::Result->from_children( | ||
| 158 | 2 | map { $self->scenario_status($_) } @{ $feature->{'scenarios'} } ); | |
| 159 | } | ||
| 160 | |||
| 161 | 16 | ▶ | sub scenario_status { |
|
Subroutine
scenario_status: called CC=1 SCAR=0.0
Pod
documented
| |||
| 162 | 16 | my ( $self, $scenario ) = @_; | |
| 163 | return Test::BDD::Cucumber::Model::Result->from_children( | ||
| 164 | 16 | map { $self->step_status($_) } @{ $scenario->{'steps'} } ); | |
| 165 | } | ||
| 166 | |||
| 167 | 55 | ▶ | sub step_status { |
|
Subroutine
step_status: called CC=1 SCAR=0.0
Pod
documented
| |||
| 168 | 55 | my ( $self, $step ) = @_; | |
| 169 | 55 | return $step->{'result'}; | |
| 170 | } | ||
| 171 | |||
| 172 | =head2 find_scenario_step_by_name | ||
| 173 | |||
| 174 | Given a Scenario and a string, searches through the steps for it and returns | ||
| 175 | the data-hash where the Step Object's C<<->text>> matches the string. | ||
| 176 | |||
| 177 | =cut | ||
| 178 | |||
| 179 | # Find a step | ||
| 180 | 3 | ▶ | sub find_scenario_step_by_name { |
|
Subroutine
find_scenario_step_by_name: called CC=1 SCAR=0.0
Pod
documented
| |||
| 181 | 3 | my ( $self, $scenario, $name ) = @_; | |
| 182 | my ($step) = | ||
| 183 | 3 | grep { $_->{'context'}->text eq $name } @{ $scenario->{'steps'} }; | |
| 184 | |||
| 185 | 3 | return $step; | |
| 186 | } | ||
| 187 | |||
| 188 | =head1 AUTHOR | ||
| 189 | |||
| 190 | Peter Sergeant C<pete@clueball.com> | ||
| 191 | |||
| 192 | =head1 LICENSE | ||
| 193 | |||
| 194 | Copyright 2019-2023, Erik Huelsmann | ||
| 195 | Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl | ||
| 196 | |||
| 197 | =cut | ||
| 198 | |||
| 199 | 11 | 1; | |