我正在尝试将黄瓜表中的数据与哈希数组进行比较。
Cucumber step:
Then I expect tasks created with:
| issuetype | summary | status |
| Task | Please review | To do |
| Task | Please review | To do |
我使用以下内容将表格转换为哈希:
Then (/^I expect tasks created with:/) do |table|
table = table.hashes
end
[{"issuetype"=>"Task",
"summary"=>"Please review",
"status"=>"To do",
"assignee"=>"unassigned",
"assigned group"=>"rm-group1"},
{"issuetype"=>"Task",
"summary"=>"Please review",
"status"=>"To do",
"assignee"=>"unassigned",
"assigned group"=>"rm-group2"}]
如何从下面的数据中选择值(issuetype
,summary
,status
),这是一个JSON解析并将其格式化为上面的table.hashes
并比较它们?
tasks [ {
id: 1
fields:{
summary: "Summary"
}
status:{
description: "description"
currentstatus: "To do"
}
issuetype{
id: "5"
name: "sub-task"
}
}]
答案 0 :(得分:0)
我希望table.hashes
为:
[
{ issuetype: 'Task', summary: 'Please review', status: 'To do' },
{ issuetype: 'Task 2', summary: 'Please review', status: 'To do' },
]
要从你的tasks
(这显然是一个无效的对象)中比较哈希数组,因此我不得不对它的真实结构做出假设:
mapped = tasks.map do |hash|
{
issuetype: hash[:issuetype][:name],
summary: hash[:fields][:summary],
status: hash[:status][:currentstatus]
}
end
现在可以比较table.hashes
和mapped
。 NB 上面的解决方案假设哈希键是符号。无论它们是否是弦乐,都要进行各自的演员表。