0

Using pact to verify if the response header matches for the consumer and provider. Running the pact verification on the provider side gives me the following error:

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

However, when I inspect if my response header, it gives me the expected value ("xyz").

Here is the sample pact file I'm trying to verify:

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

I’m new to pact. Any help would be appreciated.

  • The standard convention for header naming is "Abc" (first letter captialized), and the Rack middleware will be performing some translations on your "abc" and turning it in to "Abc" along the way. Try with that format. – Beth Skurrie Nov 08 '17 at 02:03
  • Hi @BethSkurrie, I tried it wit that. I am getting the same issue that the header value was nil. However, when I'm debugging/printing it out on the console (response.headers[:abc]) or (response.headers[:Abc]), I see the expected value is present. – user8901251 Nov 08 '17 at 14:26
  • Here is a working example https://github.com/pact-foundation/pact-ruby-e2e-example See if you can recreate the issue – Beth Skurrie Nov 09 '17 at 22:25

1 Answers1

1

While this is an old post, I hope this will help anyone who views this. I'm not familiar with ruby, however if your using a basic HTTP Rest request you need to add the accept headers on the 'withRequest' as well as the expected headers on the 'withRespondWith'. You can use Postman to view both request and response headers; JavaScript Example:

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" },
...
Beosfreak
  • 31
  • 1
  • 4