Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for in-step data tables #144

Open
lutzj82 opened this issue Jun 12, 2015 · 16 comments
Open

Add support for in-step data tables #144

lutzj82 opened this issue Jun 12, 2015 · 16 comments

Comments

@lutzj82
Copy link

lutzj82 commented Jun 12, 2015

I get that there is support for Where|Example tables, where the scenario is executed for each row.
I'm looking for the support of datatables such that:

Given a list of integers:
| integers |
| 19 |
| 3 |
| 56 |

.given("a list of integers:", function( datatable ) { } );

where datatable follows the structure proposed by:

https://github.com/cucumber/cucumber-tck

specifically:

https://github.com/cucumber/cucumber-tck/blob/master/data_tables.feature

Thanks!
-jamie

@cressie176
Copy link
Member

Agree it would be a useful feature. I'm flat out with other, stuff at present so yadda isn't event getting a lookin at the moment. Will keep it on the list and try to get round to it.

@cressie176
Copy link
Member

I'm not keen on the triple quote syntax. Instead I'm thinking of the following for single columns

Scenario: Data Tables Scenario
Given a list of integers
   ----
   1000
   2022
   9405
   ----
library.given('a list of integers $list', function(list) {
   // [1000, 2022, 9405]
})

and this for multiple columns

Scenario: Data Tables Scenario
Given a table of data:
    ------------
    left | right
    1    | 3
    2    | 4
    ------------
library.given('a table of data $table', function(table) {
   // [{ left: 1, right: 3}, {left: 2, right: 4}]
})

Finally for multi line columns...

Scenario: Data Tables Scenario
Given some shakespeare
    -----------------------------------------------------
    Henry V                     | Romeo and Juliet
    ----------------------------|------------------------
    Once more unto the          | What light from yonder
    breech dear friends         | window breaks
    ----------------------------|------------------------
    And sheathed their          | It is the East
    swords for lack of argument | and Juliet is the sun
    -----------------------------------------------------
library.given('a table of data $table', function(table) {
   /*
   [
    { 'Henry V': 'Once more unto the\nbreech dear friends', 'Romeo and Juliet': 'What light from yonder\nwindow breaks'},
    { 'Henry V': 'And sheathed their\nswords for lack of argument', 'Romeo and Juliet': 'It is the East\nand Juliet is the sun'}
  ]
  */
})

@AlbanMinassian
Copy link
Contributor

Spaces characters they'll be taken into account as well?

Scenario: Data Tables Scenario
Given some shakespeare
    -----------------------------------------------------
    Henry V                     | Romeo and Juliet
    ----------------------------|------------------------
    Once                        |    What
       breech                   | window
    ----------------------------|------------------------
      And                       | It 
    swords                      |   and 
    -----------------------------------------------------

library.given('a table of data', function(table) {
   /*
   [
    { 'Henry V': 'Once\n    breech', 'Romeo and Juliet': '    What\nwindow'},
    { 'Henry V': '  And\nswords', 'Romeo and Juliet': 'It\n   and'}
  ]
  */
})

Thanks
Ami44

@cressie176
Copy link
Member

Yes, indentation will be maintained

@AlbanMinassian
Copy link
Contributor

thank

@riaan53
Copy link

riaan53 commented Jul 19, 2015

Hi,

Will you also support examples/where blocks "[ ]" in the in step tables?

Feature: 100 Green Bottles
  Scenario: Data Tables Scenario
    Given a table of [z] data
      left | right
      [x]  | 3
       2   | [y]

     Where:
       x   | y  | z
       2   | 98 | 3
       10  | 90 | 7
       100 | 0  | 8
  library.given('a table of data', function(number, table, next) {
    // First iteration [{ left: 2, right: 3}, {left: 2, right: 98}] and number = 3 
    // Second iteration [{ left: 10, right: 3}, {left: 2, right: 90}] and number = 7
    // And so on..
  })

Im busy evaluating yadda to possibly switch my cucumber.js tests over - im running into some restrictions and hopefully yadda can help :)

Thank you.

Regards,
Riaan

@cressie176
Copy link
Member

Good idea, shouldn't be too hard if I can get the rest working. I was looking into this issue a bit yesterday, and it might be harder than I first thought. The Yadda interpreter takes a list of strings rather than a richer object. I found out yesterday that changing this can break Moonraker.

Plan B is to implement dictionary converters, which is something I've wanted for a long time, but quite tricky. With this in place the feature parser would parse multiline steps (with example table support as normal) into a single string containing \n characters.

The dictionary converter would parse the single string into a list, table etc. When you came to implement the step you would have to do something like...

dictionary.define('table', /(.+)/, tableConverter)
library.given('A table of data: $table', function(table, next) {
   /*
   [
    { 'Henry V': 'Once\n    breech', 'Romeo and Juliet': '    What\nwindow'},
    { 'Henry V': '  And\nswords', 'Romeo and Juliet': 'It\n   and'}
  ]
  */
}

@riaan53
Copy link

riaan53 commented Jul 20, 2015

Looks great!

@cressie176
Copy link
Member

Dictionary converters are in, but it's going to take a little longer to get the multiline steps.

@cressie176
Copy link
Member

Multiline steps are available in 0.15.0. Just need to write the converters to parse the above.

@riaan53
Copy link

riaan53 commented Jul 22, 2015

Awesome!

Thanks a lot.

@cressie176
Copy link
Member

I've released Yadda 0.15.2 which includes multline steps with list and single line data tables. Multiline tables i.e.

Scenario: Data Tables Scenario
Given some shakespeare
    -----------------------------------------------------
    Henry V                     | Romeo and Juliet
    ----------------------------|------------------------
    Once more unto the          | What light from yonder
    breech dear friends         | window breaks
    ----------------------------|------------------------
    And sheathed their          | It is the East
    swords for lack of argument | and Juliet is the sun
    -----------------------------------------------------

are going to be a bit harder.

@riaan53
Copy link

riaan53 commented Jul 29, 2015

@cressie176 thx for al the work on this!

Will tables work nice with with examples/where blocks in them?

@cressie176
Copy link
Member

Feature: 100 Green Bottles
  Scenario: Data Tables Scenario
    Given a table of [z] data
      left | right
      [x]  | 3
       2   | [y]

     Where:
       x   | y  | z
       2   | 98 | 3
       10  | 90 | 7
       100 | 0  | 8

The example you posted above already works.

@riaan53
Copy link

riaan53 commented Aug 1, 2015

👍

@lolmaus
Copy link

lolmaus commented Feb 28, 2018

This helped me a lot: https://github.com/acuminous/yadda/blob/master/examples/data-tables/library.js

Though I don't fully understand what's going on there. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants