File Coverage

blib/lib/Test/BDD/Cucumber/Model/Result.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1 13     13   166 use v5.14;
  13         47  
2 13     13   79 use warnings;
  13         26  
  13         657  
3              
4             package Test::BDD::Cucumber::Model::Result 0.86;
5              
6             =head1 NAME
7              
8             Test::BDD::Cucumber::Model::Result - Encapsulates a result state
9              
10             =head1 VERSION
11              
12             version 0.86
13              
14             =head1 DESCRIPTION
15              
16             Encapsulation of result state - whether that's for a step, scenario, or feature
17              
18             =cut
19              
20 13     13   84 use Moo;
  13         35  
  13         93  
21 13     13   4884 use Types::Standard qw( Enum Str );
  13         80  
  13         120  
22              
23             =head1 ATTRIBUTES
24              
25             =head2 result
26              
27             Enum of: C, C, C or C. C is used
28             if there was any TODO output from a test, and C for a test that
29             wasn't run, either due to no matching step, or because a previous step failed.
30              
31             =cut
32              
33             has 'result' => ( is => 'ro', isa => Enum[qw( passing failing pending undefined )], required => 1 );
34              
35             =head2 output
36              
37             The underlying test-output that contributed to a result.
38              
39             =cut
40              
41             has 'output' => ( is => 'ro', isa => Str, required => 1 );
42              
43             =head1 METHODS
44              
45             =head2 from_children
46              
47             Collates the Result objects you pass in, and returns one that encompasses all
48             of them.
49              
50             As they may be varied, it runs through them in order of C,
51             C, C and C - the first it finds is the overall
52             result. The empty set passes.
53              
54             =cut
55              
56             sub from_children {
57 23     23 1 137 my ( $class, @children ) = @_;
58              
59             # We'll be looking for the presence of just one of any of the
60             # short-circuiting statuses, but we need to keep a sum of all the output.
61             # Passing is the default state, so we cheat and say there was one of them.
62 23         72 my %results = ( passing => 1 );
63 23         40 my $output;
64              
65 23         65 for my $child (@children) {
66              
67             # Save the status of that child
68 58         137 $results{ $child->result }++;
69              
70             # Add its output
71 58         213 $output .= $child->output . "\n";
72             }
73 23         56 $output .= "\n";
74              
75 23         60 for my $status (qw( failing undefined pending passing )) {
76 77 100       211 if ( $results{$status} ) {
77 23         571 return $class->new(
78             {
79             result => $status,
80             output => $output
81             }
82             );
83             }
84             }
85             }
86              
87             1;