-
-
Save bethesque/9d81f21d6f77650811f4 to your computer and use it in GitHub Desktop.
HTTP requests to ruby mock server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You will need ruby or the standalone mock service to run these examples. | |
$ gem install pact-mock_service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# called before suite (preferably by the framework) | |
mkdir -p /tmp/pacts | |
pact-mock-service start -p 1234 | |
# called before each test (preferably by the framework) | |
curl -XDELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions | |
echo '' | |
echo '' | |
# during test setup, in user code | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions [email protected] | |
echo '' | |
echo '' | |
# test, in user code | |
curl -XGET localhost:1234/foo | |
echo '' | |
echo '' | |
# called after each test (preferrably by the framework) | |
curl -XGET -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification | |
echo '' | |
echo '' | |
# called after suite (preferrably by the framework) | |
curl -XPOST -H "X-Pact-Mock-Service: true" localhost:1234/pact [email protected] | |
echo '' | |
pact-mock-service stop -p 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# called before suite (preferably by the framework) | |
pact-mock-service start -p 1234 | |
# called before each test (preferably by the framework) | |
curl -XDELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions | |
echo '' | |
echo '' | |
# during test setup, in user code | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions [email protected] | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions [email protected] | |
echo '' | |
echo '' | |
# test, in user code | |
curl -XGET localhost:1234/foo | |
curl -XGET localhost:1234/bar | |
echo '' | |
echo '' | |
# called after each test (preferrably by the framework) | |
curl -XGET -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification | |
echo '' | |
echo '' | |
# called after suite (preferrably by the framework) | |
curl -XPOST -H "X-Pact-Mock-Service: true" localhost:1234/pact [email protected] | |
echo '' | |
# called after suite (preferrably by the framework) | |
pact-mock-service stop -p 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# called before suite (preferably by the framework) | |
pact-mock-service start -p 1234 | |
# INTERACTION 1 | |
# called before each test (preferably by the framework) | |
curl -XDELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions | |
echo '' | |
echo '' | |
# during test setup, in user code | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions [email protected] | |
echo '' | |
echo '' | |
# test, in user code | |
curl -XGET localhost:1234/foo | |
echo '' | |
echo '' | |
# called after each test (preferrably by the framework) | |
curl -XGET -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification | |
echo '' | |
echo '' | |
# INTERACTION 2 | |
# called before each test (preferably by the framework) | |
curl -XDELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions | |
echo '' | |
echo '' | |
# during test setup, in user code | |
curl -XPOST -H "X-Pact-Mock-Service: true" -H "Content-Type: application/json" localhost:1234/interactions [email protected] | |
echo '' | |
echo '' | |
# test, in user code | |
curl -XGET localhost:1234/foo | |
echo '' | |
echo '' | |
# called after each test (preferrably by the framework) | |
curl -XGET -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification | |
echo '' | |
echo '' | |
# called after suite (preferrably by the framework) | |
curl -XPOST -H "X-Pact-Mock-Service: true" localhost:1234/pact [email protected] | |
echo '' | |
# called after suite (preferrably by the framework) | |
pact-mock-service stop -p 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "a request for foo", | |
"provider_state": "foo exists", | |
"request": { | |
"method": "get", | |
"path": "/foo" | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": { | |
"foo": "bar" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "another request for foo", | |
"provider_state": "foo exists", | |
"request": { | |
"method": "get", | |
"path": "/foo" | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": { | |
"foo": "barbarbarbar" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"description": "a request for bar", | |
"provider_state": "bar exists", | |
"request": { | |
"method": "get", | |
"path": "/bar" | |
}, | |
"response": { | |
"status": 200, | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": { | |
"foo": "bar" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"consumer" : { | |
"name": "Consumer Name" | |
}, | |
"provider": { | |
"name": "Provider Name" | |
}, | |
"pact_dir": "/tmp/pacts" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bethesque is the field
pact_dir
described somewhere in the specification? I can't seem to find it.Asking in relation to pact-foundation/pact-js#79