Bra*_*nar 21
由于表的步骤定义正在处理,您可以在表中放置一个特殊的占位符,例如字符串"TODAYS_DATE",然后用于map_column!将列中的数据处理为您想要的格式.
例如,给出下表
Given the following user records
| username | date |
| alice | 2001-01-01 |
| bob | TODAYS_DATE |
Run Code Online (Sandbox Code Playgroud)
在您的步骤定义中,您将拥有
Given /^the following user records$/ do |table|
table.map_column!('date') do |date|
if date == 'TODAYS_DATE'
date = Time.now.strftime("%Y-%m-%d")
end
date
end
table.hashes.each do |hash|
#Whatever you need to do
end
end
Run Code Online (Sandbox Code Playgroud)
请注意,这只会在您请求哈希时更改值.table和table.raw将保持不变,但只要你需要行哈希,它们就会被map_column中的代码转换!
我知道自问这个问题已经很久了,但我最近和Cucumber做了类似的事情,所以如果有人感兴趣,这里有另一种解决方案......
Given the following user records
| username | date |
| bob | Time.now.strftime("%Y-%m-%d") |
Run Code Online (Sandbox Code Playgroud)
然后在你的步骤定义中只需eval()日期字符串
Given /^the following user records$/ do |table|
table.hashes.each do |hash|
date = eval(hash["date"])
end
end
Run Code Online (Sandbox Code Playgroud)
虽然不像布兰登的例子,但是如果没有进一步的逻辑,这也不会让你输入确切的日期.
| 归档时间: |
|
| 查看次数: |
18348 次 |
| 最近记录: |