Ruby 我如何添加或附加到我的黄瓜表?

Ruby 我如何添加或附加到我的黄瓜表?,ruby,cucumber,Ruby,Cucumber,在cucumber中,最好的特性之一是表数据传递。但是,如果我想向其中添加其他数据,或者在步骤定义中创建表数据,我该如何做呢?什么类型的表(散列?映射?列表?数组?) 为了说明这一点,下面是我的步骤之一,从特性中接受表数据,并传递给函数。我想给它添加一些数据。我怎么能这么做 Then(/^posted JSON should have the below attributes$/) do |table| ## Here I want to append some data to my tab

在cucumber中,最好的特性之一是表数据传递。但是,如果我想向其中添加其他数据,或者在步骤定义中创建表数据,我该如何做呢?什么类型的表(散列?映射?列表?数组?)

为了说明这一点,下面是我的步骤之一,从特性中接受表数据,并传递给函数。我想给它添加一些数据。我怎么能这么做

Then(/^posted JSON should have the below attributes$/) do |table|
  ## Here I want to append some data to my table. How to do it?
  posted_json_attribute_table_check table
end
然后我有一个函数,可以使用它与读取的JSON进行比较

def posted_json_attribute_table_check(table)
  json = JSON.parse $post_result.lines.first 

  data = table.raw
  data.each do |entry|
    status = entry[0]
    value = entry[1]
    expect(json[status].to_s).to eq(value)
  end
end

谢谢

表对象的类型为Cucumber::Core::Ast::DataTable,可以在此处找到

# Creates a new instance. +raw+ should be an Array of Array of String
# or an Array of Hash
# You don't typically create your own DataTable objects - Cucumber will do
# it internally and pass them to your Step Definitions.
#
def initialize(raw, location)
  raw = ensure_array_of_array(rubify(raw))
  verify_rows_are_same_length(raw)
  @raw = raw.freeze
  @location = location
end