From 8567deff150b25b3094140be07df5fd145b4228c Mon Sep 17 00:00:00 2001 From: jtsternberg Date: Fri, 9 Aug 2013 02:21:51 -0400 Subject: [PATCH] Add a new test, "should end with a table containing rows:" --- features/steps/basic_steps.php | 34 ++++++++++++++++++++++++++++++++++ features/upgradables.feature | 7 +++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/features/steps/basic_steps.php b/features/steps/basic_steps.php index 6d84fdc6..74d494b5 100644 --- a/features/steps/basic_steps.php +++ b/features/steps/basic_steps.php @@ -190,6 +190,40 @@ $steps->Then( '/^STDOUT should be a table containing rows:$/', } ); +$steps->Then( '/^STDOUT should end with a table containing rows:$/', + function ( $world, TableNode $expected ) { + $output = $world->result->STDOUT; + $outputRows = explode( "\n", rtrim( $output, "\n" ) ); + + $expectedRows = array(); + foreach ( $expected->getRows() as $row ) { + $expectedRows[] = $world->replace_variables( implode( "\t", $row ) ); + } + + $remainingRows = array(); + $start = false; + foreach( $outputRows as $key => $row ) { + + // the first row is the header and must be present + if ( $expectedRows[0] == $row ) + $start = true; + + if ( $start ) + $remainingRows[] = $row; + } + + if ( ! $start ) + throw new \Exception( $output ); + + unset($remainingRows[0]); + unset($expectedRows[0]); + $matches = array_intersect( $expectedRows, $remainingRows ); + + if ( count( $expectedRows ) != count( $matches ) ) + throw new \Exception( $output ); + } +); + $steps->Then( '/^STDOUT should be JSON containing:$/', function ( $world, PyStringNode $expected ) { $output = $world->result->STDOUT; diff --git a/features/upgradables.feature b/features/upgradables.feature index a7fe00a8..fc9c3227 100644 --- a/features/upgradables.feature +++ b/features/upgradables.feature @@ -98,10 +98,9 @@ Feature: Manage WordPress themes and plugins """ Showing 1 of """ - And STDOUT should contain: - """ - - """ + And STDOUT should end with a table containing rows: + | name | slug | + | | | Examples: | type | type_name | item | item_title | version | zip_file | file_to_check | -- 2.11.0