r54228 - in /branches/upstream/libtest-cukes-perl/current: Changes MANIFEST Makefile.PL examples/ lib/Test/Cukes.pm t/runtest-with-arg.t t/runtest-without-defined-steps.t t/runtest.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Sat Mar 13 19:39:54 UTC 2010
Author: jawnsy-guest
Date: Sat Mar 13 19:39:47 2010
New Revision: 54228
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=54228
Log:
[svn-upgrade] Integrating new upstream version, libtest-cukes-perl (0.09)
Removed:
branches/upstream/libtest-cukes-perl/current/examples/
Modified:
branches/upstream/libtest-cukes-perl/current/Changes
branches/upstream/libtest-cukes-perl/current/MANIFEST
branches/upstream/libtest-cukes-perl/current/Makefile.PL
branches/upstream/libtest-cukes-perl/current/lib/Test/Cukes.pm
branches/upstream/libtest-cukes-perl/current/t/runtest-with-arg.t
branches/upstream/libtest-cukes-perl/current/t/runtest-without-defined-steps.t
branches/upstream/libtest-cukes-perl/current/t/runtest.t
Modified: branches/upstream/libtest-cukes-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/Changes?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/Changes (original)
+++ branches/upstream/libtest-cukes-perl/current/Changes Sat Mar 13 19:39:47 2010
@@ -1,4 +1,7 @@
# Revision history for Perl extension Test::Cukes
+
+0.09:
+- Tristan Pratt makes it more compatible when using it with other Test::Bulder::Module-based tools.
0.08:
- allow step definitions to be defined in all namespaces.
Modified: branches/upstream/libtest-cukes-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/MANIFEST?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/MANIFEST (original)
+++ branches/upstream/libtest-cukes-perl/current/MANIFEST Sat Mar 13 19:39:47 2010
@@ -1,5 +1,4 @@
Changes
-examples/test.pl
inc/Module/Install.pm
inc/Module/Install/AuthorTests.pm
inc/Module/Install/Base.pm
Modified: branches/upstream/libtest-cukes-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/Makefile.PL?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/Makefile.PL (original)
+++ branches/upstream/libtest-cukes-perl/current/Makefile.PL Sat Mar 13 19:39:47 2010
@@ -1,13 +1,13 @@
use inc::Module::Install;
+
name 'Test-Cukes';
+perl_version '5.008';
all_from 'lib/Test/Cukes.pm';
-perl_version '5.008';
-
requires
- "Carp::Assert" => "0.20",
- "Any::Moose" => "0.07",
- "Exporter::Lite" => "0.02";
+ "Carp::Assert" => "0.20",
+ "Any::Moose" => "0.07",
+ "Test::Builder::Module" => "0.80";
tests 't/*.t';
author_tests 'xt';
Modified: branches/upstream/libtest-cukes-perl/current/lib/Test/Cukes.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/lib/Test/Cukes.pm?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/lib/Test/Cukes.pm (original)
+++ branches/upstream/libtest-cukes-perl/current/lib/Test/Cukes.pm Sat Mar 13 19:39:47 2010
@@ -1,12 +1,12 @@
package Test::Cukes;
use strict;
use warnings;
-use Exporter::Lite;
-use Test::More;
use Test::Cukes::Feature;
use Carp::Assert;
-our $VERSION = "0.08";
+use base 'Test::Builder::Module';
+
+our $VERSION = "0.09";
our @EXPORT = qw(feature runtests Given When Then assert affirm should shouldnt);
our @missing_steps = ();
@@ -29,15 +29,7 @@
$feature->{$caller} = Test::Cukes::Feature->new($feature_text);
}
- my $total_tests = 0;
-
my @scenarios_of_caller = @{$feature->{$caller}->scenarios};
-
- for my $scenario (@scenarios_of_caller) {
- $total_tests += @{$scenario->steps};
- }
-
- Test::More::plan(tests => $total_tests);
for my $scenario (@scenarios_of_caller) {
my $skip = 0;
@@ -47,7 +39,7 @@
SKIP:
for my $step_text (@{$scenario->steps}) {
my ($pre, $step) = split " ", $step_text, 2;
- Test::More::skip($step, 1) if $skip;
+ Test::Cukes->skip($step, 1) if $skip;
$gwt = $pre if $pre =~ /(Given|When|Then)/;
@@ -55,12 +47,12 @@
for my $step_pattern (keys %$steps) {
my $cb = $steps->{$step_pattern}->{code};
- if ($step =~ m/$step_pattern/) {
- eval { $cb->(); };
- Test::More::ok(!$@, $step_text);
+ if (my (@matches) = $step =~ m/$step_pattern/) {
+ eval { $cb->(@matches); };
+ Test::Cukes->builder->ok(!$@, $step_text);
if ($@) {
- Test::More::diag($@);
+ Test::Cukes->builder->diag($@);
$skip = 1;
$skip_reason = "Failed: $step_text";
}
@@ -77,6 +69,10 @@
}
}
+ # If the user doesn't specify tests explicitly when they use Test::Cukes;,
+ # assume they had no plan and call done_testing for them.
+ Test::Cukes->builder->done_testing if !Test::Cukes->builder->has_plan;
+
report_missing_steps();
return 0;
@@ -84,11 +80,11 @@
sub report_missing_steps {
return if @missing_steps == 0;
- Test::More::note("There are missing step definitions, fill them in:");
+ Test::Cukes->builder->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";
- Test::More::note($msg);
+ Test::Cukes->builder->note($msg);
}
}
@@ -122,8 +118,8 @@
Write your test program like this:
# test.pl
- use Test::More;
use Test::Cukes;
+ # use Test::Cukes tests => 3;
feature(<<TEXT);
Feature: writing behavior tests
@@ -137,8 +133,9 @@
Then it should pass
TEXT
- Given qr/the test program is running/, sub {
- assert "running";
+ Given qr/the (.+) program is (.+)/, sub {
+ my ($program_name, $running_or_failing) = @_;
+ assert "running program '$program_name'";
};
When qr/it reaches this step/, sub {
@@ -163,23 +160,31 @@
Test::Cukes is a testing tool inspired by Cucumber
(L<http://cukes.info>). It lets your write your module test with
-scenarios. It is supposed to be used with L<Test::More> or other
-family of C<Test::*> modules. It uses L<Test::More::note> function
+scenarios. It may be used with L<Test::More> or other family of
+TAP C<Test::*> modules. It uses L<Test::Builder::note> function
internally to print messages.
This module implements the Given-When-Then clause only in English. To
uses it in the test programs, feed the feature text into C<feature>
function, defines your step handlers, and then run all the tests by
-calling C<runtests>. Each steps should use C<assert> instead of C<ok>
-or C<is> to verify desired result.
-
-If any assertion in the Given block failed, the the corresponding
-C<When> and C<Then> blocks are skipped.
+calling C<runtests>. Step handlers may be defined in separate modules,
+as long as those modules are included before C<runtests> is called.
+Each step may use either C<assert> or standard TAP functions such as
+C<Test::Simple>'s C<ok> or C<Test::More>'s C<is> to verify desired
+result. If you specify a plan explicitly, you should be aware that
+each step line in your scenario runs an additional test, and will
+therefore add to the number of tests you must indicate.
+
+If any assertion in the Given block failed, the following C<When> and
+C<Then> blocks are all skipped.
You don't need to specify the number of tests with C<plan>. Each step
block itself is simply one test. If the block died, it's then
considered failed. Otherwise it's considered as passing.
+In the call to L<Test::Cukes::runtests>, L<done_testing> will automatically
+be called for you if you didn't specify a plan.
+
Test::Cukes re-exports C<assert> function from C<Carp::Assert> for you
to use in the step block.
@@ -189,6 +194,10 @@
=head1 AUTHOR
Kang-min Liu E<lt>gugod at gugod.orgE<gt>
+
+=head1 CONTRIBUTORS
+
+Tatsuhiko Miyagawa, Tristan Pratt
=head1 SEE ALSO
Modified: branches/upstream/libtest-cukes-perl/current/t/runtest-with-arg.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/t/runtest-with-arg.t?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/t/runtest-with-arg.t (original)
+++ branches/upstream/libtest-cukes-perl/current/t/runtest-with-arg.t Sat Mar 13 19:39:47 2010
@@ -18,7 +18,11 @@
push @passed, 3;
assert @passed == 3;
- assert( @{[ 1, 2, 3 ]} == @passed );
+ # We can't use is_deeply because Test::More doesn't play nice with
+ # Cukes's plan.
+ assert 1 == $passed[0];
+ assert 2 == $passed[1];
+ assert 3 == $passed[2];
};
runtests(<<FEATURE_TEXT);
Modified: branches/upstream/libtest-cukes-perl/current/t/runtest-without-defined-steps.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/t/runtest-without-defined-steps.t?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/t/runtest-without-defined-steps.t (original)
+++ branches/upstream/libtest-cukes-perl/current/t/runtest-without-defined-steps.t Sat Mar 13 19:39:47 2010
@@ -1,7 +1,7 @@
#!/usr/bin/env perl -w
use strict;
-use Test::Cukes;
use Test::More;
+use Test::Cukes tests => 2;
feature(<<FEATURE_TEXT);
Feature: foo
@@ -9,13 +9,18 @@
I want to bleh
Scenario: blehbleh
- Given blah1
+ Given I am a missing person
When blah2
Then blah3
FEATURE_TEXT
+# This regex shouldn't match.
+my $hit_given = 0;
+When qr/I am a missing (animal|alien)/i => sub {
+ $hit_given = 1;
+};
+
runtests;
+is($hit_given, 0, "Correctly never ran the 'when' test");
ok(@Test::Cukes::missing_steps == 3);
-pass; # two dummise
-pass;
Modified: branches/upstream/libtest-cukes-perl/current/t/runtest.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-cukes-perl/current/t/runtest.t?rev=54228&op=diff
==============================================================================
--- branches/upstream/libtest-cukes-perl/current/t/runtest.t (original)
+++ branches/upstream/libtest-cukes-perl/current/t/runtest.t Sat Mar 13 19:39:47 2010
@@ -1,6 +1,7 @@
#!/usr/bin/env perl -w
use strict;
use Test::Cukes;
+use Test::More;
feature(<<FEATURE_TEXT);
Feature: foo
@@ -8,29 +9,42 @@
I want to bleh
Scenario: blehbleh
- Given blah1
- When blah2
- Then blah3
+ Given I will say the word 'cake'
+ When it is my birthday
+ Then we will eat 28 cakes
FEATURE_TEXT
my @passed;
+my @regex_matches;
-Given qr/blah1/ => sub {
+Given qr/I will say the word '(.+)'/ => sub {
push @passed, 1;
+ push @regex_matches, @_;
- assert @passed == 1;
+ assert @passed == 1;
+ assert @regex_matches == 1
};
-When qr/blah2/ => sub {
+When qr/it is my birthday/ => sub {
push @passed, 2;
- assert @passed == 2;
+
+ ok 1, "Using is, ok, etc no longer screw up Cuke's test plan and cause"
+ . " it to fail.";
+
+ assert @passed == 2;
+ assert @regex_matches == 1
};
-Then qr/blah3/ => sub {
+Then qr/we will eat (\d+) (.+)/ => sub {
push @passed, 3;
- assert @passed == 3;
+ push @regex_matches, @_;
- assert( @{[ 1, 2, 3 ]} == @passed );
+ assert @passed == 3;
+ assert @regex_matches == 3;
+
+ is_deeply [1, 2, 3], \@passed, "Steps were called in the correct order";
+ is_deeply ['cake', 28, 'cakes'], \@regex_matches, "Regex matches were"
+ . " correctly passed to the step functions";
};
runtests;
More information about the Pkg-perl-cvs-commits
mailing list