Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ruby_version: ["2.7", "3.0", "3.1", "3.2", "3.3"]
os: ["ubuntu-latest","windows-latest","macos-latest"]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@master
with:
ruby-version: ${{ matrix.ruby_version }}
- run: "bundle install"
env:
PACT_RUBY_V2_ENABLE: 'true'
- run: "bundle exec rake pact:spec"
- run: "bundle exec rake pact:v2:spec"
- run: cat spec/pacts/test_message_consumer-test_message_producer.json
- run: bundle exec rake pact:verify
shell: bash
if: matrix.os != 'windows-latest'
- run: bundle exec rake pact:v2:verify
if: matrix.os != 'windows-latest' # no kafka on windows
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
/test/tmp/
/test/version_tmp/
/tmp/

Gemfile.lock
log/
reports/
# Used by dotenv library to load environment variables.
# .env

Expand Down
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

20 changes: 18 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ group :development, :test do

gem 'rspec'

gem 'pact'
# gem 'pact'

gem 'pact-message'

gem 'rake'
end
if ENV['X_PACT_DEVELOPMENT']
gem 'pact', path: '../pact-ruby'
else
gem 'pact', git: 'https://github.com/safdotdev/pact-ruby.git', branch: 'feat/pact-ruby-v2-conditional-install'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
gem 'combustion'
gem 'webmock'

end

# required to process messages in pact-ruby-v2
unless RUBY_PLATFORM =~ /win32|x64-mingw32|x64-mingw-ucrt/
gem "sbmt-kafka_consumer", ">= 2.0.1"
gem "sbmt-kafka_producer", ">= 1.0"
end
# gem "karafka-rdkafka", ">= 0.20.0"
81 changes: 0 additions & 81 deletions Gemfile.lock

This file was deleted.

21 changes: 20 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require 'pact/tasks'
require 'pact/tasks'

require 'rspec/core/rake_task'

ENV['PACT_RUBY_V2_ENABLE'] = 'true'
ENV['PACT_RUBY_V1_ENABLE'] = 'true'

RSpec::Core::RakeTask.new('pact:v2:spec') do |task|
task.pattern = 'spec/pact/providers/**/*_spec.rb'
task.rspec_opts = ['-t pact_v2']
end
RSpec::Core::RakeTask.new('pact:spec') do |task|
task.pattern = 'spec/service_consumers/*_spec.rb'
task.rspec_opts = ['-t pact']
end

RSpec::Core::RakeTask.new('pact:v2:verify') do |task|
task.pattern = 'spec/pact/consumers/**/*_spec.rb'
task.rspec_opts = ['-t pact_v2']
end
13 changes: 8 additions & 5 deletions spec/consumer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'pact/message/consumer/rspec'
require 'pact/consumer'
require 'pact/reification'
require 'support/pact_spec_helper.rb'
require_relative '../app/consumers/test_message_consumer.rb'

describe TestMessageConsumer, pact: true do
describe TestMessageConsumer, :pact do

subject(:consumer) {TestMessageConsumer.new}

Expand All @@ -11,9 +13,9 @@
# See app/producers/test_message_producer.rb.

expected_payload = {
"email": "jane@example.com",
"first_name": "Jane",
"last_name": "Doe"
"email": Pact.like("jane@example.com"),
"first_name": Pact.like("Jane"),
# "last_name": Pact.like("Doe") # uncomment to see failure in provider code
}

# Notice the new pact: :message decorator/metadata
Expand All @@ -28,6 +30,7 @@
test_message_producer.given("A customer is created")
.is_expected_to_send("a customer created message")
# .with_metadata()
# .with_content(Pact.like(expected_payload.to_json))
.with_content(expected_payload)

test_message_producer.send_message_string do | content_string |
Expand All @@ -44,7 +47,7 @@
# This failure would indicate a mismatch between the consumers expectations of the message format and what the producer actually sends.

it "Successfully consumes the message and creates a pact contract file" do
expect(@message).to eq(expected_payload.to_json)
expect(@message).to eq(Pact::Reification.from_term(expected_payload).to_json)
end

end
Expand Down
24 changes: 19 additions & 5 deletions spec/pacts/test_message_consumer-test_message_producer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,36 @@
"providerStates": [
{
"name": "A customer is created",
"params": {
}
"params": {}
}
],
"contents": {
"email": "jane@example.com",
"first_name": "Jane",
"last_name": "Doe"
"first_name": "Jane"
},
"matchingRules": {
"body": {
"$.email": {
"matchers": [
{
"match": "type"
}
]
},
"$.first_name": {
"matchers": [
{
"match": "type"
}
]
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
"version": "3.0.0"
}
}
}
1 change: 1 addition & 0 deletions spec/support/pact_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Pact.message_consumer "Test Message Consumer" do
has_pact_with "Test Message Producer" do
mock_provider :test_message_producer do
pact_specification_version '3'
end
end
end
Loading