【发布时间】:2023-03-07 11:26:02
【问题描述】:
鉴于 JSON 响应:
{
"tags": [
{
"id": 81499,
"name": "sign-in"
},
{
"id": 81500,
"name": "user"
},
{
"id": 81501,
"name": "authentication"
}
]
}
使用 RSpec 2,我想验证此响应是否包含带有名称身份验证的标签。作为一个相当新的 Ruby,我认为有一种比迭代数组和使用 include 检查名称的每个值更有效的方法?或地图/收集。我可以简单地使用正则表达式来检查 /authentication/i 但这似乎也不是最好的方法。
这是我目前的规格:
it "allows filtering" do
response = @client.story(15404)
#response.tags.
end
【问题讨论】: