Chart-Timecard
view release on metacpan or search on metacpan
inc/Test/Cukes.pm view on Meta::CPAN
#line 1
package Test::Cukes;
use strict;
use warnings;
use Test::Cukes::Feature;
use Carp::Assert;
use Try::Tiny;
use base 'Test::Builder::Module';
our $VERSION = "0.10";
our @EXPORT = qw(feature runtests Given When Then assert affirm should shouldnt);
our @missing_steps = ();
my $steps = {};
my $feature = {};
sub feature {
my $caller = caller;
my $text = shift;
$feature->{$caller} = Test::Cukes::Feature->new($text)
}
sub runtests {
my $caller = caller;
my $feature_text = shift;
if ($feature_text) {
$feature->{$caller} = Test::Cukes::Feature->new($feature_text);
}
my @scenarios_of_caller = @{$feature->{$caller}->scenarios};
for my $scenario (@scenarios_of_caller) {
my $skip = 0;
my $skip_reason = "";
my $gwt;
for my $step_text (@{$scenario->steps}) {
my ($pre, $step) = split " ", $step_text, 2;
if ($skip) {
Test::Cukes->builder->skip($step_text);
next;
}
$gwt = $pre if $pre =~ /(Given|When|Then)/;
my $found_step = 0;
for my $step_pattern (keys %$steps) {
my $cb = $steps->{$step_pattern}->{code};
if (my (@matches) = $step =~ m/$step_pattern/) {
my $ok = 1;
try {
$cb->(@matches);
} catch {
$ok = 0;
};
Test::Cukes->builder->ok($ok, $step_text);
if ($skip == 0 && !$ok) {
Test::Cukes->builder->diag($@);
$skip = 1;
( run in 2.158 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )