File Coverage

lib/Test/BDD/Cucumber/Loader.pm
Criterion Covered Total %
statement 35 38 92.1
branch 3 6 50.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 49 55 89.0


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