File Coverage

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


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