This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to annotated tag 0.19
in repository libtest-bdd-cucumber-perl.

commit 16d4aa6ab4731a81333407246703c14603315324
Author: Peter Sergeant <p...@peters-air-2.home>
Date:   Sun Apr 20 17:54:38 2014 +0100

    Ever noticed how much typing stuff over and over again sucks? Also: 
Method::Signatures
---
 .../digest/features/step_definitions/basic_steps.pl | 21 +++++++++++----------
 lib/Test/BDD/Cucumber/Executor.pm                   | 21 +++++++++++++++------
 lib/Test/BDD/Cucumber/StepFile.pm                   | 15 ++++++++++++++-
 3 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/examples/digest/features/step_definitions/basic_steps.pl 
b/examples/digest/features/step_definitions/basic_steps.pl
index 432f157..be571a9 100755
--- a/examples/digest/features/step_definitions/basic_steps.pl
+++ b/examples/digest/features/step_definitions/basic_steps.pl
@@ -5,26 +5,27 @@ use warnings;
 
 use Digest;
 use Test::More;
+
 use Test::BDD::Cucumber::StepFile;
-use Method::Signatures;
 
-Given qr/a usable "(\w+)" class/, func ($c) { use_ok( $1 ); };
-Given qr/a Digest (\S+) object/, func ($c) {
+Given qr/a usable "(\w+)" class/, sub { use_ok( $1 ); };
+
+Given qr/a Digest (\S+) object/, sub {
     my $object = Digest->new($1);
     ok( $object, "Object created" );
-    $c->stash->{'scenario'}->{'object'} = $object;
+    S->{'object'} = $object;
 };
 
-When qr/I've added "(.+)" to the object/, func ($c) {
-    $c->stash->{'scenario'}->{'object'}->add( $1 );
+When qr/I've added "(.+)" to the object/, sub {
+    S->{'object'}->add( $1 );
 };
 
-When "I've added the following to the object", func ($c) {
-    $c->stash->{'scenario'}->{'object'}->add( $c->data );
+When "I've added the following to the object", sub {
+    S->{'object'}->add( C->data );
 };
 
-Then qr/the (.+) output is "(.+)"/, func ($c) {
+Then qr/the (.+) output is "(.+)"/, sub {
     my $method = {base64 => 'b64digest', 'hex' => 'hexdigest' }->{ $1 } ||
         do { fail("Unknown output type $1"); return };
-    is( $c->stash->{'scenario'}->{'object'}->$method, $2 );
+    is( S->{'object'}->$method, $2 );
 };
diff --git a/lib/Test/BDD/Cucumber/Executor.pm 
b/lib/Test/BDD/Cucumber/Executor.pm
index 5e77ea4..b02d586 100644
--- a/lib/Test/BDD/Cucumber/Executor.pm
+++ b/lib/Test/BDD/Cucumber/Executor.pm
@@ -172,11 +172,11 @@ sub execute_scenario {
             feature  => $feature_stash,
             step     => {},
         },
-    
+
         # Step-specific info
         feature  => $feature,
         scenario => $outline,
-    
+
         # Communicators
         harness  => $harness,
 
@@ -200,10 +200,10 @@ sub execute_scenario {
                     %context_defaults,
                     verb => 'before',
                 });
-    
+
                 my $result = $self->dispatch( $context, $before_step,
                         $outline_stash->{'short_circuit'} );
-    
+
                 # If it didn't pass, short-circuit the rest
                 unless ( $result->result eq 'passing' ) {
                     $outline_stash->{'short_circuit'}++;
@@ -263,7 +263,7 @@ sub execute_scenario {
                     %context_defaults,
                     verb => 'after',
                 });
-    
+
                 # All After steps should happen, to ensure cleanup
                 my $result = $self->dispatch( $context, $after_step, 0 );
             }
@@ -370,7 +370,16 @@ sub dispatch {
         $context->matches([ $context->text =~ $regular_expression ]);
 
         # Execute!
-        eval { $coderef->( $context ) };
+        eval {
+            no warnings 'redefine';
+            local *Test::BDD::Cucumber::StepFile::S = sub {
+                return $context->stash->{'scenario'}
+            };
+            local *Test::BDD::Cucumber::StepFile::C = sub {
+                return $context
+            };
+            $coderef->( $context )
+        };
         if ( $@ ) {
             $Test::Builder::Test->ok( 0, "Test compiled" );
             $Test::Builder::Test->diag( $@ );
diff --git a/lib/Test/BDD/Cucumber/StepFile.pm 
b/lib/Test/BDD/Cucumber/StepFile.pm
index ec32984..5cdb46b 100755
--- a/lib/Test/BDD/Cucumber/StepFile.pm
+++ b/lib/Test/BDD/Cucumber/StepFile.pm
@@ -8,10 +8,11 @@ Test::BDD::Cucumber::StepFile - Functions for creating and 
loading Step Definiti
 
 use strict;
 use warnings;
+use Carp qw/croak/;
 
 require Exporter;
 our @ISA = qw(Exporter);
-our @EXPORT = qw(Given When Then Step Transform Before After);
+our @EXPORT = qw(Given When Then Step Transform Before After C S);
 
 our @definitions;
 
@@ -76,6 +77,18 @@ sub Transform { push( @definitions, [ Transform => @_ ] ) }
 sub Before    { push( @definitions, [ Before    => @_ ] ) }
 sub After     { push( @definitions, [ After     => @_ ] ) }
 
+=head2 C
+
+=head2 S
+
+Return the context and the Scenario stash, respectively, B<but only when called
+inside a step definition>.
+
+=cut
+
+sub S { croak "You can only call `S` inside a step definition" }
+sub C { croak "You can only call `C` inside a step definition" }
+
 =head2 load
 
 Loads a file containing step definitions, and returns a list of the steps

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libtest-bdd-cucumber-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to