【问题标题】:How could I add or append to my cucumber Table?我怎样才能添加或附加到我的黄瓜表?
【发布时间】:2015-03-25 10:30:45
【问题描述】:

在 cucumber 中,最好的特性之一是 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

谢谢!

【问题讨论】:

    标签: ruby cucumber


    【解决方案1】:

    表对象的类型是 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
    

    【讨论】:

      猜你喜欢
      • 2012-08-23
      • 2021-09-27
      • 1970-01-01
      • 2014-10-15
      • 2018-07-15
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多