OSDN Git Service

Add a new test, "should end with a table containing rows:"
authorjtsternberg <me@jtsternberg.com>
Fri, 9 Aug 2013 06:21:51 +0000 (02:21 -0400)
committerjtsternberg <me@jtsternberg.com>
Fri, 9 Aug 2013 06:21:51 +0000 (02:21 -0400)
features/steps/basic_steps.php
features/upgradables.feature

index 6d84fdc..74d494b 100644 (file)
@@ -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;
index a7fe00a..fc9c322 100644 (file)
@@ -98,10 +98,9 @@ Feature: Manage WordPress themes and plugins
       """
       Showing 1 of
       """
-    And STDOUT should contain:
-      """
-      <item_title>
-      """
+    And STDOUT should end with a table containing rows:
+      | name         | slug   |
+      | <item_title> | <item> |
 
     Examples:
       | type   | type_name | item                    | item_title              | version | zip_file                                                              | file_to_check                                                    |