File Coverage

lib/Test/BDD/Cucumber/Loader.pm
Criterion Covered Total %
statement 36 37 97.3
branch 5 6 83.3
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 52 54 96.3


line stmt bran cond sub pod time code
1 16     16   123732 use v5.14;
  16         56  
2 16     16   83 use warnings;
  16         31  
  16         1192  
3              
4             package Test::BDD::Cucumber::Loader 0.87;
5              
6             =head1 NAME
7              
8             Test::BDD::Cucumber::Loader - Simplify loading of Step Definition and feature files
9              
10             =head1 VERSION
11              
12             version 0.87
13              
14             =head1 DESCRIPTION
15              
16             Makes loading Step Definition files and Feature files a breeze...
17              
18             =head1 METHODS
19              
20             =head2 load
21              
22             Accepts a path, and returns a L object with the Step
23             Definition files loaded, and a list of L objects.
24              
25             =head2 load_steps
26              
27             Accepts an L object and a string representing either a
28             step file, or a directory containing zero or more C<*_steps.pl> files, and loads
29             the steps in to the executor; if you've used C we'll have already scanned
30             the feature directory for C<*_steps.pl> files.
31              
32             =cut
33              
34              
35 16     16   646 use Path::Class;
  16         55371  
  16         1000  
36 16     16   8625 use File::Find::Rule;
  16         143221  
  16         286  
37              
38 16     16   9757 use Test::BDD::Cucumber::Executor;
  16         81  
  16         803  
39 16     16   10173 use Test::BDD::Cucumber::Parser;
  16         82  
  16         3893  
40 16     16   138 use Test::BDD::Cucumber::StepFile();
  16         37  
  16         5357  
41              
42             sub load {
43 21     21 1 1480 my ( $class, $path ) = @_;
44              
45 21         449 my $executor = Test::BDD::Cucumber::Executor->new();
46              
47             # Either load a feature or a directory...
48 21         543 my ( $dir, $file );
49 21 100       646 if ( -f $path ) {
50 4         42 $file = file($path);
51 4         518 $dir = $file->dir;
52             } else {
53 17         278 $dir = dir($path);
54             }
55              
56             # Load up the steps
57 21         1943 $class->load_steps( $executor, $dir );
58              
59             # Grab the feature files
60             my @features = map {
61 21 100       829 my $file = file($_);
  26         34500  
62 26         3686 my $feature =
63             Test::BDD::Cucumber::Parser->parse_file( $file );
64             } (
65             $file
66             ? ( $file . '' )
67             : File::Find::Rule->file()->name('*.feature')->in($dir)
68             );
69              
70 21         473 return ( $executor, @features );
71             }
72              
73             sub load_steps {
74 21     21 1 78 my ( $class, $executor, $path ) = @_;
75              
76 21 50       224 if ( -f $path ) {
77 0         0 $executor->add_steps( Test::BDD::Cucumber::StepFile->load($path) );
78             } else {
79             $executor->add_steps( Test::BDD::Cucumber::StepFile->load($_) )
80 21         1902 for File::Find::Rule->file()->name('*_steps.pl')->in($path);
81             }
82              
83 21         277 return $class;
84             }
85              
86             =head1 AUTHOR
87              
88             Peter Sergeant C
89              
90             =head1 LICENSE
91              
92             Copyright 2019-2023, Erik Huelsmann
93             Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl
94              
95             =cut
96              
97             1;