OSDN Git Service

behat: use table in 'should be CSV containing' step
authorscribu <mail@scribu.net>
Thu, 30 May 2013 00:56:16 +0000 (03:56 +0300)
committerscribu <mail@scribu.net>
Thu, 30 May 2013 00:56:16 +0000 (03:56 +0300)
features/bootstrap/support.php
features/post.feature
features/steps/basic_steps.php
features/term.feature

index 178df3a..d213ea3 100644 (file)
@@ -97,11 +97,12 @@ function checkThatJsonStringContainsJsonString( $actualJson, $expectedJson ) {
  * Both strings are expected to have headers for their CSVs.
  * $actualCSV must match all data rows in $expectedCSV
  *
- * @return bool     Whether $actualCSV contacts $expectedCSV
+ * @param  string   A CSV string
+ * @param  array    A nested array of values
+ * @return bool     Whether $actualCSV contains $expectedCSV
  */
-function checkThatCsvStringContainsCsvString( $actualCSV, $expectedCSV ) {
+function checkThatCsvStringContainsValues( $actualCSV, $expectedCSV ) {
        $actualCSV = array_map( 'str_getcsv', explode( PHP_EOL, $actualCSV ) );
-       $expectedCSV = array_map( 'str_getcsv', explode( PHP_EOL, $expectedCSV ) );
 
        if ( empty( $actualCSV ) )
                return false;
index 0e0c3c1..035be29 100644 (file)
@@ -61,8 +61,6 @@ Feature: Manage WordPress posts
 
     When I run `wp post list --post_type='post' --fields=post_title,post_name,post_status --format=csv`
     Then STDOUT should be CSV containing:
-      """
-      post_title,post_name,post_status
-      "Publish post",publish-post,publish
-      "Draft post",,draft
-      """
+      | post_title   | post_name    | post_status  |
+      | Publish post | publish-post | publish      |
+      | Draft post   |              | draft        |
index 747de64..ec5a0fe 100644 (file)
@@ -199,11 +199,17 @@ $steps->Then( '/^STDOUT should be JSON containing:$/',
 });
 
 $steps->Then( '/^STDOUT should be CSV containing:$/',
-       function( $world, PyStringNode $expected ) {
+       function( $world, TableNode $expected ) {
                $output = $world->result->STDOUT;
-               $expected = $world->replace_variables( (string) $expected );
 
-               if ( ! checkThatCsvStringContainsCsvString( $output, $expected ) )
+               $expectedRows = $expected->getRows();
+               foreach ( $expected as &$row ) {
+                       foreach ( $row as &$value ) {
+                               $value = $world->replace_variables( $value );
+                       }
+               }
+
+               if ( ! checkThatCsvStringContainsValues( $output, $expectedRows ) )
                        throw new \Exception( $output );
        }
 );
index 7a6442d..df7dea7 100644 (file)
@@ -17,10 +17,8 @@ Feature: Manage WordPress terms
 
     When I run `wp term list post_tag --fields=name,slug --format=csv`
     Then STDOUT should be CSV containing:
-      """
-      name,slug
-      "Test term",test
-      """
+      | name      | slug |
+      | Test term | test |
 
   Scenario: Creating/deleting a term
     Given a WP install