我正在尝试从 Cucumber 中的三列内联数据表中读取数据。
特征文件:
Then I should see grades,exteriors, interiors and engines available:
|grades |exteriors | engine |
|xdata-id-Elegance |xdata-id-NH-788p | 12345 |
| |xdata-id-NH737M | |
| |xdata-id-NH731P | |
| |xdata-id-R-539P | |
步骤定义:
Then(/^I should see grades,exteriors, interiors and engines available:$/) do |table|
data = table.rows_hash
puts data['exteriors']
end
这给我的错误只允许 2 行。
有谁知道我可以访问的另一种方式,所有三列都使用表对象?
最佳答案
以更简单的方式为我工作,三列数据表如下:
Scenario: I am able to select a date range
Given I am on the rejections tracker page as a superuser
Then the date range filters work as expected
| dateFrom | dateTo | variance |
| 12/05/2014 | null | lesser than |
| null | 12/07/2014 | lesser than |
| null | null | equal to |
这对我有用:
Then(/^the date range filters work as expected$/) do |table|
data = table.hashes
date_from = []
date_to = []
variance = []
data.each do |row|
row.each do |key, value|
if key.eql? "dateFrom"
date_from << value
elsif key.eql? "dateTo"
date_to << value
elsif key.eql? "variance"
variance << value
end
end
end
puts date_from
puts date_to
puts variance
end
输出:
["12/05/2014", "null", "null"]
["null", "12/07/2014", "null"]
["lesser than", "lesser than", "equal to"]
关于ruby - cucumber 从 3 列表中读取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19909912/