Cucumber 是否将ParameterType与表数据一起使用?
我在用黄瓜和红宝石 我有一个识别货币价值并将其解析为BigDecimal的工具,例如“给定成本为25.50美元” 我希望对表执行类似的操作,即任何与模式匹配的内容都应自动转换,例如:Cucumber 是否将ParameterType与表数据一起使用?,cucumber,Cucumber,我在用黄瓜和红宝石 我有一个识别货币价值并将其解析为BigDecimal的工具,例如“给定成本为25.50美元” 我希望对表执行类似的操作,即任何与模式匹配的内容都应自动转换,例如: Given these products: | item | cost | | foo | $10.50 | | bar | $5.25 | 我在文档中找不到任何与此相关的内容。可能吗 编辑:这似乎是以前支持的,但在Cucumber 3中删除了: 表转换通过以逗号分隔的列标题列表(前缀为“t
Given these products:
| item | cost |
| foo | $10.50 |
| bar | $5.25 |
我在文档中找不到任何与此相关的内容。可能吗
编辑:这似乎是以前支持的,但在Cucumber 3中删除了:
表转换通过以逗号分隔的列标题列表(前缀为“table:”)进行匹配
在步骤定义中,确保迭代表中的所有项目,并调用步骤
,因为成本为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
您是指示例表数据还是UI表数据?@supputuri我更新了问题以澄清。您找到方法了吗?我想迁移一个很大程度上依赖于表转换的大型测试套件。谢谢,但我真的想在所有表中自动实现这一点,例如,我调用
product['cost']
,得到BigDecimal
的10.50
,而不是字符串“$10.50”
。既然成本是xxx,为什么不使用“步骤定义”或实现此功能的方法进行转换呢。您还可以选择在任何位置使用to_i
将字符串转换为十进制。