Skip to content

Commit

Permalink
let runtests function accept feature text as args.
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed Jun 21, 2009
1 parent 6b9cdd6 commit 4cb8cfc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
# Revision history for Perl extension Test::Cukes

0.06:
- let runtests accept feature text too

0.05:
- Fix the missing step report of "And" steps.

Expand Down
10 changes: 8 additions & 2 deletions lib/Test/Cukes.pm
Expand Up @@ -6,7 +6,7 @@ use Test::More;
use Test::Cukes::Feature;
use Carp::Assert;

our $VERSION = "0.05";
our $VERSION = "0.06";
our @EXPORT = qw(feature runtests Given When Then assert affirm should shouldnt);

our @missing_steps = ();
Expand All @@ -23,6 +23,12 @@ sub feature {

sub runtests {
my $caller = caller;
my $feature_text = shift;

if ($feature_text) {
$feature->{$caller} = Test::Cukes::Feature->new($feature_text);
}

my $total_tests = 0;
my @scenarios_of_caller = @{$feature->{$caller}->scenarios};

Expand Down Expand Up @@ -80,7 +86,7 @@ sub report_missing_steps {
Test::More::note("There are missing step definitions, fill them in:");
for my $step_text (@missing_steps) {
my ($word, $text) = ($step_text =~ /^(Given|When|Then) (.+)$/);
my $msg = "\n$word qr/${text}/ => sub {\n ...\n}\n";
my $msg = "\n$word qr/${text}/ => sub {\n ...\n};\n";
Test::More::note($msg);
}
}
Expand Down
33 changes: 33 additions & 0 deletions t/runtest-with-arg.t
@@ -0,0 +1,33 @@
#!/usr/bin/env perl -w
use strict;
use Test::Cukes;
my @passed;

Given qr/blah1/ => sub {
push @passed, 1;

assert @passed == 1;
};

When qr/blah2/ => sub {
push @passed, 2;
assert @passed == 2;
};

Then qr/blah3/ => sub {
push @passed, 3;
assert @passed == 3;

assert( @{[ 1, 2, 3 ]} == @passed );
};

runtests(<<FEATURE_TEXT);
Feature: foo
In order to bleh
I want to bleh
Scenario: blehbleh
Given blah1
When blah2
Then blah3
FEATURE_TEXT

0 comments on commit 4cb8cfc

Please sign in to comment.