Skip to content

Commit

Permalink
feat: init support for pact matchers and pact rust
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Aug 5, 2024
1 parent 6242caf commit 462cf19
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in pact.gemspec
gemspec

# if ENV['X_PACT_DEVELOPMENT']
# gem "pact-ffi", path: '../pact-ruby-ffi'
# end
group :test do
gem 'faraday', '~> 2.0'
gem 'faraday-retry', '~> 2.0'
Expand Down
2 changes: 2 additions & 0 deletions lib/pact/array_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def to_hash
{
:json_class => self.class.name,
:contents => contents,
'pact:matcher:type' => 'type',
:value => [contents],
:min => min
}
end
Expand Down
6 changes: 4 additions & 2 deletions lib/pact/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'pact/shared/text_differ'
require 'pact/shared/form_differ'
require 'pact/shared/multipart_form_differ'

# require 'pact/ffi/logger'

module Pact

Expand Down Expand Up @@ -45,6 +45,7 @@ def self.=~ other
attr_accessor :pact_dir
attr_accessor :log_dir
attr_accessor :tmp_dir
# attr_accessor :rust_log_level

attr_writer :logger

Expand All @@ -58,7 +59,7 @@ def self.default_configuration
c.pact_dir = File.expand_path('./spec/pacts')
c.tmp_dir = File.expand_path('./tmp/pacts')
c.log_dir = default_log_dir

# c.rust_log_level = 0
c.output_stream = $stdout
c.error_stream = $stderr
c.pactfile_write_order = :chronological
Expand Down Expand Up @@ -167,6 +168,7 @@ def is_rake_running?
end

def create_logger
# PactFfi::Logger.log_to_stdout(rust_log_level)
FileUtils::mkdir_p log_dir
logger = ::Logger.new(log_path)
logger.level = ::Logger::DEBUG
Expand Down
4 changes: 3 additions & 1 deletion lib/pact/consumer_contract/http_consumer_contract_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def pact_specification_version hash
# metadata.pactSpecificationVersion
maybe_pact_specification_version_1 = hash[:metadata] && hash[:metadata]['pactSpecification'] && hash[:metadata]['pactSpecification']['version']
maybe_pact_specification_version_2 = hash[:metadata] && hash[:metadata]['pactSpecificationVersion']
pact_specification_version = maybe_pact_specification_version_1 || maybe_pact_specification_version_2
maybe_pact_specification_version_3 = hash[:metadata] && hash[:metadata]['pactSpecificationVersion']
maybe_pact_specification_version_4 = hash[:metadata] && hash[:metadata]['pactSpecificationVersion']
pact_specification_version = maybe_pact_specification_version_1 || maybe_pact_specification_version_2 || maybe_pact_specification_version_3 || maybe_pact_specification_version_4
pact_specification_version ? Pact::SpecificationVersion.new(pact_specification_version) : Pact::SpecificationVersion::NIL_VERSION
end

Expand Down
6 changes: 5 additions & 1 deletion lib/pact/something_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ def initialize contents

def to_hash
{
# pact ruby
:json_class => self.class.name,
:contents => contents
:contents => contents,
# pact rust
'pact:matcher:type' => 'type',
'value' => contents
}
end

Expand Down
7 changes: 6 additions & 1 deletion lib/pact/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def initialize(attributes = {})
end

def to_hash
{ json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher) } }
# Pact-Ruby V2 Standard
# { json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher) } }
# Pact-Rust V2 Standard.
{ "pact:matcher:type": 'regex', value: generate, regex: fix_regexp(matcher)['s'] }
# Both
{ "pact:matcher:type": 'regex', value: generate, regex: fix_regexp(matcher)['s'], json_class: self.class.name, data: { generate: generate, matcher: fix_regexp(matcher) } }
end

def as_json(options = {})
Expand Down
1 change: 1 addition & 0 deletions pact-support.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "awesome_print", "~> 1.9"
spec.add_runtime_dependency "diff-lcs", "~> 1.5"
spec.add_runtime_dependency "expgen", "~> 0.1"
# spec.add_runtime_dependency 'pact-ffi', '~> 0.4'

spec.add_development_dependency "rspec", ">= 2.14", "< 4.0"
spec.add_development_dependency "rake", "~> 13.0"
Expand Down

0 comments on commit 462cf19

Please sign in to comment.