Skip to content

Instantly share code, notes, and snippets.

View uglyog's full-sized avatar

Ronald Holshausen uglyog

View GitHub Profile
{
"provider": {
"name": "Event API"
},
"consumer": {
"name": "Source System"
},
"interactions": [
{
"description": "A POST request with an event",
$ rake pact:verify
Using spec/service_consumers/pact_helper.rb
Verifying a pact between Source System and Event API
A post request with an event
returns a response which
has status code 201
Finished in 0.10356 seconds
1 example, 0 failures
require 'grape'
require 'models/event_repository'
require 'models/events_decorator'
require 'digest/md5'
class EventsApi < Grape::API
version 'v1', using: :accept_version_header
helpers do
require 'pact/consumer/rspec' # Require the pact rspec helper
Pact.service_consumer "Source System" do # register a consumer with pact
has_pact_with "Event API" do # register the provider that has the pact
mock_service :event_api do # register the mock service that will run and pretend to be the provider
port 1234
end
end
end
{
"provider": {
"name": "Event API"
},
"consumer": {
"name": "Source System"
},
"interactions": [
{
"description": "A POST request with an event",
POST /events HTTP/1.1
Content-Md5: CHEFLZW9taJ4sH6fxPN82Q==
X-Hmac-Date: Tue, 13 May 2014 01:21:17 GMT
Authorization: HMAC 1f5ca8529707d870bb993b10fd17ddf53971e4b4
Content-Type: application/json
Connection: close
Host: localhost:9292
Content-Length: 192
{"eventId":"13ec9646-a33b-4319-a941-dbb924a60130","timestamp":"2014-05-13 01:06:38 UTC","host":"rholshausen.local","remoteAddress":"0:0:0:0:0:0:0:1%0","eventType":"LOGIN","user":"rholshausen"}
require 'securerandom'
class Event
attr_accessor :event_id, :timestamp, :host, :remote_address, :event_type, :user
def initialize
@event_id = SecureRandom.uuid
@timestamp = Time.now
end
{
"eventId": "13ec9646-a33b-4319-a941-dbb924a60130",
"timestamp": "2014-05-13 01:06:38 UTC",
"host": "rholshausen.local",
"remoteAddress": "0:0:0:0:0:0:0:1%0",
"eventType": "LOGIN",
"user": "rholshausen"
}
require 'pact_helper'
require_relative '../lib/client'
require_relative '../lib/event'
describe SourceSystemClient, :pact => true do
let!(:now) { Time.now }
before do
subject.class.base_uri 'http://localhost:1234'
require 'pact_helper'
require_relative '../lib/client'
require_relative '../lib/event'
describe SourceSystemClient, :pact => true do
before do
subject.class.base_uri 'http://localhost:1234'
end