Skip to content

Commit 4595015

Browse files
committed
feat: add pact v2 interface
PACT_RUBY_V2_ENABLE=true to opt into new code PACT_RUBY_V1_ENABLE=false to disable old code PACT_RUBY_V1 is enabled by default PACT_RUBY_V2 is disabled by default
1 parent e6299e0 commit 4595015

File tree

125 files changed

+5997
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5997
-22
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ _yardoc
88
coverage
99
lib/bundler/man
1010
pkg
11+
# grpc generated files required for testing
12+
!spec/internal/pkg
1113
rdoc
1214
spec/reports
1315
test/tmp
@@ -28,8 +30,9 @@ log
2830
.idea
2931
reports
3032
Gemfile.lock
33+
example/**/Gemfile.lock
3134
*.gemfile.lock
32-
gemfiles/*.gemfile.lock
35+
gemfiles
3336
reports/pacts
3437
spec/examples.txt
3538
*bethtest*

.rspec_v2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--color
2+
--format progress
3+
--require spec_helper_v2
4+
--require rails_helper_v2

documentation/README_V2.md

Lines changed: 447 additions & 0 deletions
Large diffs are not rendered by default.

documentation/pact-v2-arch.png

3.21 MB
Loading

example/animal-service-v2/Gemfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
source 'https://rubygems.org'
2+
3+
group :development, :test do
4+
gem 'rspec'
5+
gem 'pact', path: '../../'
6+
gem 'pry'
7+
# required for pact-ruby-v2
8+
gem 'combustion'
9+
gem 'webmock'
10+
end
11+
12+
gem 'rake'
13+
gem 'rack'
14+
gem 'sqlite3'
15+
gem 'sequel'
16+
gem 'sinatra'
17+
18+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]

example/animal-service-v2/Rakefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$: << File.join(File.dirname(__FILE__), "lib")
2+
3+
require 'pact/tasks'
4+
5+
task :default => 'pact:verify'
6+
7+
require 'rspec/core/rake_task'
8+
9+
RSpec::Core::RakeTask.new('pact:v2:verify') do |task|
10+
task.pattern = 'spec/pact/consumers/*_spec.rb'
11+
task.rspec_opts = ['-t pact', '--require rails_helper']
12+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require File.dirname(__FILE__) + '/lib/animal_service/api'
2+
3+
run AnimalService::Api
16 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'sequel'
2+
require_relative 'db'
3+
4+
module AnimalService
5+
class AnimalRepository
6+
7+
def self.find_alligator_by_name name
8+
DATABASE[:animals].where(name: name).single_record
9+
end
10+
11+
end
12+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'sinatra/base'
2+
require_relative 'animal_repository'
3+
require 'json'
4+
5+
module AnimalService
6+
7+
class Api < Sinatra::Base
8+
9+
set :raise_errors, false
10+
set :show_exceptions, false
11+
12+
error do
13+
e = env['sinatra.error']
14+
content_type :json, :charset => 'utf-8'
15+
status 500
16+
{error: e.message, backtrace: e.backtrace}.to_json
17+
end
18+
19+
get '/alligators/:name' do
20+
if (alligator = AnimalRepository.find_alligator_by_name(params[:name]))
21+
content_type :json, :charset => 'utf-8'
22+
alligator.to_json
23+
else
24+
status 404
25+
end
26+
end
27+
28+
end
29+
end

0 commit comments

Comments
 (0)