在黄瓜中,最好的功能之一是Table数据传递。但是,如果我想向其中添加其他数据,或者在我的step_definitions中创建表数据,我该怎么办呢? Table(hash?map?list?array?)是什么类型的?
为了说明,下面是我的一步,接受来自该功能的表数据,并传递给一个函数。我想向它添加一些数据。我怎么能这样做?
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
谢谢!
答案 0 :(得分:0)
表对象的类型为Cucumber :: Core :: Ast :: DataTable,可在此处找到。 https://github.com/cucumber/cucumber-ruby-core/blob/master/lib/cucumber/core/ast/data_table.rb
# 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