简体   繁体   English

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

[英]unorthodox cucumber…creating a Cucumber::Ast::Table in a step definition

Context: 语境:

I'm in a regular situation that commonly uses Cucumber as a solution. 我经常使用Cucumber作为解决方案。 I'm trying to use Cucumber on a team with unique needs when it comes to translation and shared understanding. 在翻译和共享理解方面,我正在尝试将Cucumber用于具有独特需求的团队。 The gist of the problem is that some people cannot use detailed, literal, information on what is being tested (I will call that the concretes), other people need to share an understanding of the concretes, etc. 问题的关键在于,有些人不能使用详细的,字面的,有关正在测试的内容的信息(我称之为混凝土),其他人需要分享对混凝土的理解等。

Problem Statement: 问题陈述:

I have a want to make a Cucumber::Ast::Table inside a step definition. 我想在步骤定义中制作一个Cucumber::Ast::Table I think the community may benefit from @current_table = Cucumber::Ast::Table.new expects an argument in its initializer. 我认为社区可能会受益于@current_table = Cucumber::Ast::Table.new期望在其初始化器中有一个参数。

My attempted situation didn't work: 我的尝试情况不起作用:

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

Because it failed with this error: 因为它失败了这个错误:

undefined method `transpose' for "\\n|this|that|\\n|1|2|\\n":String undefined方法`transpose'代表“\\ n | this | that | \\ n | 1 | 2 | \\ n”:String

It looks like you might be able to use the parse method: 看起来你可以使用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

I am not sure what the last 2 parameters of the parse method are used for, but using nil seems to work fine for a simple case. 我不确定解析方法的最后两个参数是用于什么的,但是使用nil似乎对于一个简单的情况很好。

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

The ::new method is claimed to expect an array of arrays. 声称:: new方法需要一个数组数组。 On another page I read it may also support an array of hashes . 在另一个页面上,我读到它也可能支持一系列哈希 But not sure about that. 但不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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