Subject: | Fix for Test::Builder 1.5 |
These are two patches to fix Test::BDD::Cucumber for Test::Builder 1.5.
Test::Builder->details is no longer populated by default. This is a measure to save memory. As a replacement, TB2::History now stores statistical information which is usually what you want.
Test::Builder->details is no longer populated by default. This is a measure to save memory. As a replacement, TB2::History now stores statistical information which is usually what you want.
Subject: | 0002-Implement-results-analysis-using-Test-Builder-1.5.patch |
From 60b464f4d4aa82f616cc6683689b4b5c1c5747b4 Mon Sep 17 00:00:00 2001
From: "Michael G. Schwern" <schwern@pobox.com>
Date: Sun, 14 Apr 2013 18:25:43 +0100
Subject: [PATCH 2/2] Implement %results analysis using Test::Builder 1.5.
Test::Builder->details no longer works because it doesn't store events by default
to save memory. Rather than turning event storage on, it's better to use the
TB2::History statistical methods.
---
lib/Test/BDD/Cucumber/Executor.pm | 44 ++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 8 deletions(-)
diff --git lib/Test/BDD/Cucumber/Executor.pm lib/Test/BDD/Cucumber/Executor.pm
index b4780c4..260608c 100644
--- lib/Test/BDD/Cucumber/Executor.pm
+++ lib/Test/BDD/Cucumber/Executor.pm
@@ -302,7 +302,7 @@ sub dispatch {
# Close up the Test::Builder object
$tb_return->{'builder'}->done_testing();
- my $status = $self->_test_status($tb_return);
+ my $status = $self->_test_status($tb_return->{builder});
# Create the result object
$result = Test::BDD::Cucumber::Model::Result->new({
@@ -321,8 +321,22 @@ sub dispatch {
sub _test_status {
- my $self = shift;
- my $tb_return = shift;
+ my $self = shift;
+ my $builder = shift;
+
+ my $results = $builder->can("history") ? $self->_test_status_from_history($builder)
+ : $self->_test_status_from_details($builder);
+
+
+ # Turn that in to a Result status
+ return $results->{'fail'} ? 'failing' :
+ $results->{'todo'} ? 'pending' :
+ 'passing' ;
+}
+
+sub _test_status_from_details {
+ my $self = shift;
+ my $builder = shift;
# Make a note of test status
my %results = map {
@@ -335,15 +349,29 @@ sub _test_status {
} else {
( fail => 1 )
}
- } $tb_return->{'builder'}->details;
+ } $builder->details;
- # Turn that in to a Result status
- return $results{'fail'} ? 'failing' :
- $results{'todo'} ? 'pending' :
- 'passing' ;
+ return \%results;
}
+sub _test_status_from_history {
+ my $self = shift;
+ my $builder = shift;
+
+ my $history = $builder->history;
+
+ my %results;
+ $results{todo} = $history->todo_count ? 1 : 0;
+ $results{fail} = !$history->test_was_successful;
+ $results{pass} = $history->pass_count ? 1 : 0;
+
+ return \%results;
+}
+
+
+
+
=head2 skip_step
Accepts a step-context, a result-type, and a textual reason, exercises the
--
1.8.0.3
Subject: | 0001-Extract-code-to-turn-the-test-results-into-a-status.patch |
From 5403806145145a578ee50e1c976e749348b73ab7 Mon Sep 17 00:00:00 2001
From: "Michael G. Schwern" <schwern@pobox.com>
Date: Sun, 14 Apr 2013 18:20:08 +0100
Subject: [PATCH 1/2] Extract code to turn the test results into a status.
In preparation for adapting this to Test::Builder 1.5
---
lib/Test/BDD/Cucumber/Executor.pm | 47 ++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git lib/Test/BDD/Cucumber/Executor.pm lib/Test/BDD/Cucumber/Executor.pm
index 468ce06..b4780c4 100644
--- lib/Test/BDD/Cucumber/Executor.pm
+++ lib/Test/BDD/Cucumber/Executor.pm
@@ -302,25 +302,7 @@ sub dispatch {
# Close up the Test::Builder object
$tb_return->{'builder'}->done_testing();
- # Make a note of test status
- my %results = map {
- if ( $_->{'ok'} ) {
- if ( $_->{'type'} eq 'todo' || $_->{'type'} eq 'todo_skip' ) {
- ( todo => 1)
- } else {
- ( pass => 1 )
- }
- } else {
- ( fail => 1 )
- }
- } $tb_return->{'builder'}->details;
-
- # Turn that in to a Result status
- my $status = $results{'fail'} ?
- 'failing' :
- $results{'todo'} ?
- 'pending' :
- 'passing';
+ my $status = $self->_test_status($tb_return);
# Create the result object
$result = Test::BDD::Cucumber::Model::Result->new({
@@ -337,6 +319,31 @@ sub dispatch {
}
}
+
+sub _test_status {
+ my $self = shift;
+ my $tb_return = shift;
+
+ # Make a note of test status
+ my %results = map {
+ if ( $_->{'ok'} ) {
+ if ( $_->{'type'} eq 'todo' || $_->{'type'} eq 'todo_skip' ) {
+ ( todo => 1)
+ } else {
+ ( pass => 1 )
+ }
+ } else {
+ ( fail => 1 )
+ }
+ } $tb_return->{'builder'}->details;
+
+ # Turn that in to a Result status
+ return $results{'fail'} ? 'failing' :
+ $results{'todo'} ? 'pending' :
+ 'passing' ;
+}
+
+
=head2 skip_step
Accepts a step-context, a result-type, and a textual reason, exercises the
@@ -372,4 +379,4 @@ Copyright 2011, Peter Sergeant; Licensed under the same terms as Perl
=cut
-1;
\ No newline at end of file
+1;
--
1.8.0.3