协议验证:失败/错误:期望(header_value).to match_header(名称,expected_head



使用 pact 验证使用者和提供者的响应标头是否匹配。在提供程序端运行协议验证会给我以下错误:

Failure/Error: expect(header_value).to match_header(name, expected_header_value)
Expected header "abc" to equal "xyz", but was nil

但是,当我检查我的响应标头是否时,它会给我预期值("xyz")。

这是我尝试验证的示例协议文件:

"interactions": [
{
  "description": "a request to do something",
  "request": {
    "method": "get",
    "path": "/example"
  },
  "response": {
    "status": 200,
    "headers": {
      "abc": "xyz"
    }
  }
}]

我是新来的。任何帮助将不胜感激。

虽然这是一个旧帖子,但我希望这能帮助任何查看此内容的人。我不熟悉 ruby,但是如果您使用基本的 HTTP Rest 请求,则需要在"withRequest"上添加接受标头,在"withRespondWith"上添加预期的标头。您可以使用邮递员查看请求和响应标头;JavaScript 示例:

describe('When a request is made to get all <resources>', () => {
    beforeAll(() =>
      provider.setup().then(() => {
        provider.addInteraction({
          uponReceiving: 'a request to receive to receive all...',
          withRequest: {
            method: 'GET',
            path: '/<resource>',
            // Default headers from Axios documentation
            headers: { Accept: "application/json, text/plain, */*" }
          },
...
willRespondWith: {
            // expected headers
            headers: { "Content-Type": "application/json; charset=utf-8" },
...

最新更新