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 a6f8112674d8f85b9205612c966a12e66916d7f7
Author: Peter Sergeant <pete@Peters-MacBook-Air-2.local>
Date:   Sat May 31 15:30:26 2014 +0100

    Updated the documentation to better reflect the use of C and S
---
 lib/Test/BDD/Cucumber.pm                  | 14 +++-----
 lib/Test/BDD/Cucumber/Manual/Steps.pod    | 26 +++++++++------
 lib/Test/BDD/Cucumber/Manual/Tutorial.pod | 53 +++++++++++++++++--------------
 lib/Test/BDD/Cucumber/StepContext.pm      | 17 +++++++++-
 4 files changed, 68 insertions(+), 42 deletions(-)

diff --git a/lib/Test/BDD/Cucumber.pm b/lib/Test/BDD/Cucumber.pm
index 04307bd..b7108fe 100644
--- a/lib/Test/BDD/Cucumber.pm
+++ b/lib/Test/BDD/Cucumber.pm
@@ -14,18 +14,12 @@ L<Cucumber on Perl on 
MetaCPAN|https://metacpan.org/release/Test-BDD-Cucumber>
 
 =head1 WARNING
 
-This is beta software, at best. The interface is unlikely to undergo major
-incompatible changes, but it's certainly possible. Do have a read of the
-B<Bugs and Missing> section below so you're not surprised when these things
-don't work.
+Do have a read of the B<Bugs and Missing> section below so you're not surprised
+when things don't work.
 
 In almost all cases, where the behaviour of this module is different from
 the I<real> Cucumber, the plan is to move it to be more similar to that.
 
-The idea is that the first 1.0 release will be the first production release and
-before that, you're on your own. There are many things still to add, but B<I'm>
-using it to do Real Things already.
-
 =head1 NEXT STEPS
 
 If you are B<completely new to Cucumber>, you'd get a pretty overview from
@@ -73,10 +67,12 @@ in the very near future:
 
 On Github, of course: L<https://github.com/sheriff/test-bdd-cucumber-perl>.
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Peter Sergeant C<p...@clueball.com>
 
+Ben Rodgers C<b...@bdr.org>
+
 =head1 LICENSE
 
 Copyright 2011, Peter Sergeant; Licensed under the same terms as Perl
diff --git a/lib/Test/BDD/Cucumber/Manual/Steps.pod 
b/lib/Test/BDD/Cucumber/Manual/Steps.pod
index 013e326..7fb89e4 100644
--- a/lib/Test/BDD/Cucumber/Manual/Steps.pod
+++ b/lib/Test/BDD/Cucumber/Manual/Steps.pod
@@ -41,24 +41,32 @@ step definitions, and gives us the C<func()> keyword you'll 
see in a minute.
 
 =head1 STEP DEFINITIONS
 
- Given qr/I have (\d+)/, func ($c) {
-    $c->stash->{'scenario'}->{'count'} += $1;
+ Given qr/I have (\d+)/, sub {
+    S->{'count'} += $1;
  }
 
- When "The count is an integer", func ($c) {
-    $c->stash->{'scenario'}->{'count'} =
-        int( $c->stash->{'scenario'}->{'count'} );
+ When "The count is an integer", sub {
+    S->{'count'} =
+        int( S->{'count'} );
  }
 
  Then qr/The count should be (\d+)/, func ($c) {
-    is( $c->stash->{'scenario'}->{'count'}, $c->matches->[0], "Count matches" 
);
+    is( S->{'count'}, C->matches->[0], "Count matches" );
  }
 
 Each of the exported verb functions accept a regular expression (or a string
 that's used as one), and a coderef. The coderef is passed a single argument,
-the L<Test::BDD::Cucumber::StepContext> object. To make this a little prettier,
-we use L<Method::Signatures>'s C<func()> keyword so we're not continually
-typing: C<sub { my $c = shift; ... >.
+the L<Test::BDD::Cucumber::StepContext> object. Before the subref is executed,
+localized definitions of C<S> and C<C> are set, such that the lines below are
+equivalent:
+
+  # Access the first match
+  sub { my $context = shift; print $context->matches->[0] }
+  sub { C->matches->[0] }
+
+  # Set a value in the scenario-level stash
+  sub { my $context = shift; my $stash = $context->stash; $stash->{'count'} = 
1 }
+  sub { S->{'count'} = 1 }
 
 We will evaluate the regex immediately before we execute the coderef, so you
 can use $1, $2, $etc, although these are also available via the StepContext.
diff --git a/lib/Test/BDD/Cucumber/Manual/Tutorial.pod 
b/lib/Test/BDD/Cucumber/Manual/Tutorial.pod
index ebf5cbb..24761c3 100644
--- a/lib/Test/BDD/Cucumber/Manual/Tutorial.pod
+++ b/lib/Test/BDD/Cucumber/Manual/Tutorial.pod
@@ -65,25 +65,25 @@ C<features/step_definitions/basic_steps.pl> file in it:
  use Test::BDD::Cucumber::StepFile;
  use Method::Signatures;
 
- Given qr/a usable (\S+) class/, func ($c) { use_ok( $1 ); };
- Given qr/a Digest (\S+) object/, func ($c) {
+ Given qr/a usable (\S+) 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 );
  };
 
 When you run L<pherkin|App::Pherkin> or the Test::Builder-based test which does
@@ -124,20 +124,11 @@ separately, they'll just subsume the steps in to the 
other scenarios.
 
 This is matched by:
 
- Given qr/a usable (\S+) class/, func ($c) { use_ok( $1 ); };
+ Given qr/a usable (\S+) class/, sub { use_ok( $1 ); };
 
 C<Given()> is a function exported by L<Test::BDD::Cucumber::StepFile> that
 accepts two arguments: a regular expression (or a string when you don't need
-to do any smart matching) and a coderef. We use L<Method::Signatures> to save
-some typing here, so note that written longer hand, the above might be written:
-
- Given(
-     qr/a usable (\S+) class/,
-     sub {
-        my $c = shift;
-        use_ok( $1 );
-     };
- );
+to do any smart matching) and a coderef.
 
 If you're paying attention, you might notice that C<use_ok> comes from
 L<Test::More>. B<Each step is run, from a> L<Test::Builder> B<perspective, as
@@ -158,10 +149,13 @@ L<Test::BDD::Cucumber::Manual::Steps>.
 The first scenario is delimited from the previous steps by a blank line, and
 it's called I<Check MD5>. Scenarios are marked out using the C<Scenario:>
 keyword, and just like the Background section before, it's a series of steps.
+
 These steps rely on the step before, which means we can examine the
 L<Test::Builder::StepContext|context> object C<$c> a little more closely.
 
- Given qr/a Digest (\S+) object/, func ($c) {
+ Given qr/a Digest (\S+) object/, sub {
+    my $c = shift;
+
     my $object = Digest->new($1);
     ok( $object, "Object created" );
     $c->stash->{'scenario'}->{'object'} = $object;
@@ -180,6 +174,19 @@ contains evertything that step should need to execute. 
We'll be looking at some
 of the methods you can call against it as we look at other steps, and you can
 find complete documentation for it here: L<Test::Builder::StepContext>.
 
+You'll note that the code above differs from the very first example, where we
+made use of C<C> and C<S>. C<C> is a function which returns the current 
context,
+and C<S> is a function which returns the scenario stash. So the above can be
+written:
+
+ Given qr/a Digest (\S+) object/, sub {
+    my $c = shift;
+
+    my $object = Digest->new($1);
+    ok( $object, "Object created" );
+    S->{'object'} = $object;
+ };
+
 This scenario also introduce several ways of starting a step, I<Given>, 
I<When>,
 and I<Then>, as well as I<And>. These are used to organize steps by type, with
 I<Given> tending to describe setup steps, I<When> describing the key actions
@@ -232,8 +239,8 @@ C<pystring>s, and conceptually similar to HEREDOCs. The 
contents of the string
 will be available to the step definition via the C<data()> method of the
 I<context>:
 
- 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 );
  };
 
 While we don't have an example of it here, you can also provide tables to your
diff --git a/lib/Test/BDD/Cucumber/StepContext.pm 
b/lib/Test/BDD/Cucumber/StepContext.pm
index 7ad5563..ceb74b0 100644
--- a/lib/Test/BDD/Cucumber/StepContext.pm
+++ b/lib/Test/BDD/Cucumber/StepContext.pm
@@ -13,6 +13,15 @@ The coderefs in Step Definitions have a single argument 
passed to them, a
 C<Test::BDD::Cucumber::StepContext> object. This is an attribute-only class,
 populated by L<Test::BDD::Cucumber::Executor>.
 
+When steps are run normally, C<C()> is set directly before execution to return
+the context; this allows you to do:
+
+  sub { return C->columns }
+
+instead of:
+
+  sub { my $c = shift; return $c->columns; }
+
 =head1 ATTRIBUTES
 
 =head2 columns
@@ -42,6 +51,12 @@ The stash allows you to persist data across features, 
scenarios, or steps
 (although the latter is there for completeness, rather than having any useful
 function).
 
+The scenario-level stash is also available to steps by calling C<S()>, making
+the following two lines of code equivalent:
+
+ sub { my $context = shift; my $stash = $context->stash; $stash->{'count'} = 1 
}
+ sub { S->{'count'} = 1 }
+
 =cut
 
 has 'stash'    => ( is => 'ro', required => 1, isa => 'HashRef' );
@@ -180,7 +195,7 @@ sub transform
     my $value = shift;
 
     defined $value or return $value;
-        
+
     TRANSFORM:
     for my $transformer ( @{ $self->transformers } )
     {

-- 
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