acuminous / yadda

A BDD javascript library
412 stars 73 forks source link

Multiline examples table with an inline multiline data table #181

Closed xeladotbe closed 9 years ago

xeladotbe commented 9 years ago

Hi,

I would like to use the multiline examples tables with an inline multiline data table, but unfortunately this throws an error. (example below)

Incorrect number of fields in example table. Expected 2 but found 4

Is there any solution to get this work? (I'm using the latest yadda version - 0.15.5)

Feature: Feature name

  Scenario: Scenario name

    When [when]
    then expect something like this

     -------------------------------------
     x        |   y
     [then]
     -------------------------------------

  Examples:

    when                  | then
    ----------------------|-----------------------
    something             | foo        |   bar
                          | bar        |   foo
    ----------------------|-----------------------
    something else        | bar        |   foo
                          | foo        |   bar
cressie176 commented 9 years ago

The problem is that you have two columns headings in your example table, but three data values, however I suspect the deeper problem is that you may be using the wrong tool for the job.

The purpose of example tables is for when you have a scenario that you want to execute with multiple values, e.g.

Scenario: Customers are charged VAT according to their country of consumption

Given Fred is in [country]
When he buys a song for £10.00
Then he is charged [vat]

Example:
country    | vat
-----------|---------
France     | 2.00
USA        | 0.00

The above is clear and easy to follow (the whole point of BDD), but has less of the boilerplate than if you wrote two almost identical scenarios.

What I think you are trying to do is reduce the boilerplate of writing BDD tests still further by using a combination of example tables and multiline steps, but at the cost of clarity.

If this is your intention then I'd suggest generating your specifications using a templating tool like hogan or handlebars. You could do this dynamically as your tests run, or as a pre-test step.

xeladotbe commented 9 years ago

Thank you for the fast response. That's what I'm currently trying, maybe you have a suggestion to do this with pure yadda features.

Feature: I should be able to order some tariffs

  Scenario: order [tariff]

     When I open the page /a-page-name
      and I add [tariff] to my shopping cart
     then I should be able to check a domain

     When I decide to choose my domain later
     then I should see my shopping cart as described below

      ---------------------------------------
      id     |   variant     | firstbilling
      [basket]
      ---------------------------------------

     When I finish my order
     then I expect an order confirmation

  Examples:

  tariff                          | basket
  --------------------------------|-------------------------------------
  tariff-one                      | tariff-one    | campaign    |  0.00
                                  | addon-one     | default     |  0.00
  --------------------------------|-------------------------------------
  tariff-two                      | tariff-two    | campaign    |  9.99
                                  | addon-one     | default     |  0.00
                                  | addon-two     | default     |  1.99
  --------------------------------|-------------------------------------
  tariff-three                    | tariff-three  | campaign    | 19.99
                                  | addon-two     | default     |  0.00
                                  | addon-three   | default     |  3.99
cressie176 commented 9 years ago

Thanks, I understand better now. One thing you could try, although I've no idea if it will work, is to use a combination of the pipe and field separator character (\u2506), e.g.

Feature: I should be able to order some tariffs

  Scenario: order [tariff]

     When I open the page /a-page-name
      and I add [tariff] to my shopping cart
     then I should be able to check a domain

     When I decide to choose my domain later
     then I should see my shopping cart as described below

      ---------------------------------------
      id     ┆   variant     ┆ firstbilling
      [basket]
      ---------------------------------------

     When I finish my order
     then I expect an order confirmation

  Examples:

  tariff                          | basket
  --------------------------------|-------------------------------------
  tariff-one                      | tariff-one    ┆ campaign    ┆  0.00
                                  | addon-one     ┆ default     ┆  0.00
  --------------------------------|-------------------------------------
  tariff-two                      | tariff-two    ┆ campaign    ┆  9.99
                                  | addon-one     ┆ default     ┆  0.00
                                  | addon-two     ┆ default     ┆  1.99
  --------------------------------|-------------------------------------
  tariff-three                    | tariff-three  ┆ campaign    ┆ 19.99
                                  | addon-two     ┆ default     ┆  0.00
                                  | addon-three   ┆ default     ┆  3.99
xeladotbe commented 9 years ago

Hi @cressie176,

thank you! First I tried

  tariff                          | basket
  --------------------------------|-------------------------------------
  tariff-one                      | tariff-one    ┆ campaign    ┆  0.00
                                  | addon-one     ┆ default     ┆  0.00
  --------------------------------|-------------------------------------
  tariff-two                      | tariff-two    ┆ campaign    ┆  9.99
                                  | addon-one     ┆ default     ┆  0.00
                                  | addon-two     ┆ default     ┆  1.99
  --------------------------------|-------------------------------------
  tariff-three                    | tariff-three  ┆ campaign    ┆ 19.99
                                  | addon-two     ┆ default     ┆  0.00
                                  | addon-three   ┆ default     ┆  3.99

but this doesn't work, instead of the previous error I got:

Incorrect number of fields in example table. Expected 2 but found 3

and then I tried

  tariff                          ┆ basket
  --------------------------------┆-------------------------------------
  tariff-one                      ┆ tariff-one    | campaign    |  0.00
                                  ┆ addon-one     | default     |  0.00
  --------------------------------┆-------------------------------------
  tariff-two                      ┆ tariff-two    | campaign    |  9.99
                                  ┆ addon-one     | default     |  0.00
                                  ┆ addon-two     | default     |  1.99
  --------------------------------┆-------------------------------------
  tariff-three                    ┆ tariff-three  | campaign    | 19.99
                                  ┆ addon-two     | default     |  0.00
                                  ┆ addon-three   | default     |  3.99

and it works :)

yadda is such a great tool - I like it!

Regards, Alex

cressie176 commented 9 years ago

Glad you like it, but can't claim all the credit. The multiline tables were a contribution from @thr0w.