gpt4 book ai didi

cucumber - 将 ParameterType 与表数据一起使用?

转载 作者:行者123 更新时间:2023-12-05 07:23:32 25 4
gpt4 key购买 nike

我将 Cucumber 与 Ruby 结合使用。

我有一个 ParameterType它识别货币值并将它们解析为 BigDecimal,例如“鉴于成本是 25.50 美元”。

我想对表格做类似的事情,即任何匹配模式的东西都应该自动转换,例如:

Given these products:
| item | cost |
| foo | $10.50 |
| bar | $5.25 |

我无法在文档中找到任何关于此的信息。可能吗?

编辑:这似乎曾经被 Step Argument Transforms 支持但这些在 Cucumber 3 中被删除了:

A table transform is matched via a comma-delimited list of the column headers prefixed with 'table:'

最佳答案

在步骤定义中,确保遍历表中的所有项目并调用步骤Given the cost is XXX

这是步骤def中的示例逻辑

And(/^Given these products:$/) do |table|
# iterate through table
table.hashes.each do |product|
# you can get the product details here
item = product['item']
cost = product['cost']
# you can use the item if you want to select or any operation
# calling the Given the cost is xx step (here calling the step that already you implemented)
step("Given the cost is #{cost}")
end
end

关于cucumber - 将 ParameterType 与表数据一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55944335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com