在黄瓜中使用列表 data-table

Using a list in a Cucumber data-table

是否可以在 Cucumber 数据中使用事物列表 table?

一个可能的例子是安排会议。 我有一个会议,有固定的日期、主题和参加者名单,我想在我的验收测试中查看。

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

我如何正确地通过服务员列表进行测试?这可能吗?我只能找到构成列表的 single-column table 的示例,但我需要在此处嵌套一些内容。

对于我的测试,我只是像您一样使用一个特殊的分隔符,然后在 .rb 文件中解析出结果。

例如有这个更复杂的例子:

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

我的解析代码如下:

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

希望这对您有所帮助:-)

有多种方法可以将小黄瓜 table 映射到胶水参数:

  • bean 列表,请参阅 github
  • 中的示例
  • cucumber.api.Datatable
  • 的实例
  • 地图列表
  • 字符串列表列表