4

我正在对黄瓜使用 rspec 期望。似乎在黄瓜步骤中使用多个期望时,黄瓜会评估它们,直到它们中的第一个失败。但是,我还想继续运行其他期望以清楚地了解问题所在。我能以某种方式实现这一目标吗?

示例:-假设 response = "1",code = "2" 和 status = "3"

expect(response).to eq("0")
expect(code).to eq("2")
expect(status).to eq("1")

Cucumber 在评估响应变量时会失败。但我想检查其他两个变量的值并获得错误状态值的输出。这可能吗?

4

1 回答 1

3

最简单的是:

expect({
  response: response,
  code: code,
  status: status}
).to eq({ response: "0", code: "2", status: "1" })

如果测试失败,您会看到两个哈希值比较,差异清晰可见。

于 2015-11-20T10:41:40.800 回答