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