forked from pact-foundation/pact-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(message pact): add DSL for configuring Message Pact verifications
- Loading branch information
Showing
7 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'pact/provider/configuration/service_provider_dsl' | ||
|
||
module Pact | ||
module Provider | ||
module Configuration | ||
class MessageProviderDSL < ServiceProviderDSL | ||
class RackToMessageAdapter | ||
def initialize(message_builder) | ||
@message_builder = message_builder | ||
end | ||
|
||
def call(env) | ||
request_body_json = JSON.parse(env['rack.input'].read) | ||
contents = @message_builder.call(request_body_json['description']) | ||
[200, {"Content-Type" => "application/json"}, [{ contents: contents }.to_json]] | ||
end | ||
end | ||
|
||
def initialize name | ||
super | ||
@mapper_block = lambda { |args| } | ||
end | ||
|
||
dsl do | ||
def builder &block | ||
self.app_block = lambda { RackToMessageAdapter.new(block) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'pact/message' | ||
|
||
# Example data store | ||
|
||
class DataStore | ||
def self.greeting_recipient= greeting_recipient | ||
@greeting_recipient = greeting_recipient | ||
end | ||
|
||
def self.greeting_recipient | ||
@greeting_recipient | ||
end | ||
end | ||
|
||
# Example message producer | ||
|
||
class BarProvider | ||
def create_message | ||
{ | ||
text: "Hello #{DataStore.greeting_recipient}" | ||
} | ||
end | ||
end | ||
|
||
# Provider states | ||
|
||
Pact.provider_states_for "Foo" do | ||
provider_state "a world exists" do | ||
set_up do | ||
DataStore.greeting_recipient = "world" | ||
end | ||
end | ||
end | ||
|
||
CONFIG = { | ||
"a message" => lambda { BarProvider.new.create_message } | ||
} | ||
|
||
Pact.message_provider "Bar" do | ||
builder { |description| CONFIG[description].call } | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'pact/tasks' | ||
|
||
Pact::VerificationTask.new(:message) do | pact | | ||
pact.uri 'spec/pacts/foo-bar-message.json', pact_helper: 'spec/support/message_spec_helper.rb' | ||
end |
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