非正统的黄瓜...在步骤定义中创建黄瓜:: Ast ::表

时间:2013-12-19 19:37:11

标签: ruby cucumber

上下文

我经常使用Cucumber作为解决方案。在翻译和共享理解方面,我正在尝试将Cucumber用于具有独特需求的团队。问题的关键在于,有些人不能使用详细的,字面的,有关正在测试的内容的信息(我称之为混凝土),其他人需要分享对混凝土的理解等。

问题陈述:

我想在步骤定义中创建Cucumber::Ast::Table。我认为社区可能会受益于@current_table = Cucumber::Ast::Table.new期望在其初始化程序中存在一个参数。

我的尝试情况不起作用:

Given(/^an example step that has very well written english but can be misinterpreted and may not be concrete enough for some team members$/) do
  @current_table = Cucumber::Ast::Table.new('''
    | concrete1 | concrete2 |
    | value1    | value2    |
  ''')
end

因为失败了这个错误:

未定义的方法`transpose'代表“\ n | this | that | \ n | 1 | 2 | \ n”:String

2 个答案:

答案 0 :(得分:3)

您似乎可以使用parse方法:

Given(/^an example step that has very well written english but can be misinterpreted and may not be concrete enough for some team members$/) do
  @current_table = Cucumber::Ast::Table.parse('''
    | concrete1 | concrete2 |
    | value1    | value2    |
  ''', nil, nil)

  p @current_table.class
  #=> Cucumber::Ast::Table

  p @current_table.raw
  #=> [["concrete1", "concrete2"], ["value1", "value2"]]
end

我不确定解析方法的最后两个参数是用于什么的,但是对于一个简单的情况,使用nil似乎工作正常。

答案 1 :(得分:0)

http://cukes.info/api/cucumber/ruby/yardoc/Cucumber/Ast/Table.html#initialize-instance_method

声称:: new方法需要一个数组数组。在另一个页面上,我读到它也可能支持array of hashes。但不确定。

相关问题