简体   繁体   中英

Using a list in a Cucumber data-table

is it possible to use a list of things in a Cucumber data table?

A possible example is to schedule a meeting. I have a meeting with a set date, topic and a list of attendants which i want to check in my acceptance test.

Feature:
   Scenario:
      Given I want to save a meeting with the following set of data
      | Date | Attendants | Topic
      | 2017-03-12 | Jobs, Steve; Reznik, Trevor | Beer is great
      Then is the data successfully saved

How do i correctly pass a list of attendants to the test? Is this possible at all? I could only find examples of single-column tables that make up lists, but I need something nested here.

For my tests, I simply use a special delimiter like you are doing and then parse out the result in the .rb file.

A have this more complex example for instance:

  And there are results:
     | sequence        | user   | steps                       |
     | Style Test 1    | tracy  | 1;0;pass 2;1;fail 4;1;fail  |

And my parsing code looks like:

Given(/^there are results:$/) do |table|

  table.hashes.each do |s|

     sequence = Sequence.where(name: s[:sequence]).first
     result = FactoryGirl.build(:sequence_result)
     result.sequence = sequence._id.to_s
     result.user = User.where(name: s[:user]).first._id.to_s

     s[:steps].split(" ").each do |st|
        step = FactoryGirl.build(:step_result)

        parts = st.split(";")
        step.step = sequence.steps[parts[0].to_i]._id.to_s
        step.answer = parts[1]
        step.pass = parts[2] == "pass"

        result.step_results << step
     end

     result.save

  end

end

Hope this helps :-)

There is a variety of ways you can map a gherkin table to a glue parameter:

  • List of beans, see an example at github
  • instance of cucumber.api.Datatable
  • List of maps
  • List of lists of strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM