使用pact验证响应标头是否与使用者和提供者匹配。在提供者端运行pact验证时会出现以下错误:
Failure/Error: expect(header_value).to match_header(name, expected_header_value)
Expected header "abc" to equal "xyz", but was nil然而,当我检查我的响应头时,它给出了期望值("xyz")。
下面是我正在尝试验证的示例pact文件:
"interactions": [
{
"description": "a request to do something",
"request": {
"method": "get",
"path": "/example"
},
"response": {
"status": 200,
"headers": {
"abc": "xyz"
}
}
}]我是pact新手。任何帮助都将不胜感激。
发布于 2021-02-05 04:33:33
虽然这是一个古老的帖子,但我希望这会对任何人有帮助。我不熟悉ruby,但是如果你使用一个基本的HTTP Rest请求,你需要在'withRequest‘上添加accept头,以及在'withRespondWith’上添加预期的头。您可以使用Postman查看请求和响应头;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" },
...https://stackoverflow.com/questions/47162569
复制相似问题