Skip to content

Commit

Permalink
Merge pull request #141 from YOU54F/ruby_3_1
Browse files Browse the repository at this point in the history
Ruby 3 1
  • Loading branch information
YOU54F authored May 17, 2023
2 parents c51b79c + be1dfca commit d576b4c
Show file tree
Hide file tree
Showing 22 changed files with 145 additions and 103 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release_gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: '3.1'
- run: "bundle install"
# - name: Test
# run: bundle exec rake
- name: Test
run: bundle exec rake

release:
needs: test
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/test.yml.hangs → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ on: [push, pull_request]

jobs:
test:
runs-on: "ubuntu-latest"
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
ruby_version: ["2.2", "2.7"]
experimental: [false]
include:
- ruby_version: "3.0"
experimental: true
ruby_version: ["2.7","3.0","3.1"]
os: ["ubuntu-latest","windows-latest","macos-latest"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion lib/pact/mock_service/interactions/interaction_mismatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def to_hash
def to_s
[
"Diff with interaction: #{candidate_interaction.description_with_provider_state_quoted}",
diff_formatter.call(diff, {colour: false})
diff_formatter.call(diff, **{colour: false})
].join("\n")
end

Expand Down
3 changes: 1 addition & 2 deletions pact-mock_service.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'thor', '>= 0.19', '< 2.0'
gem.add_runtime_dependency 'json'
gem.add_runtime_dependency 'webrick', '~> 1.3'
gem.add_runtime_dependency 'term-ansicolor', '~> 1.0'
gem.add_runtime_dependency 'pact-support', '~> 1.16', '>= 1.16.4'
gem.add_runtime_dependency 'filelock', '~> 1.1'

gem.add_development_dependency 'rack-test', '~> 0.7'
gem.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
gem.add_development_dependency 'webmock', '~> 3.4'
gem.add_development_dependency 'pry'
gem.add_development_dependency 'fakefs', '~> 0.4'
gem.add_development_dependency 'fakefs', '~> 2.4'
gem.add_development_dependency 'hashie', '~> 2.0'
gem.add_development_dependency 'activesupport', '~> 5.1'
gem.add_development_dependency 'faraday', '~> 0.12'
Expand Down
4 changes: 2 additions & 2 deletions spec/features/administration_endpoints_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@

context "when the Origin header is set" do
it "sets the Access-Control-Allow-Origin header to be the Origin" do
options '/pact', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'X-Pact-Mock-Service, Content-Type', 'HTTP_ORIGIN' => 'http://localhost:1234' }
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:1234'
options '/pact', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'X-Pact-Mock-Service, Content-Type', 'HTTP_ORIGIN' => 'http://localhost:8888' }
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:8888'
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/features/log/mock_multiple_responses_spec.log
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ Missing requests:
GET /alligators



WARN -- : Missing requests:
GET /alligators
GET /alligators



36 changes: 36 additions & 0 deletions spec/features/log/mock_one_response_spec.log
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,44 @@ WARN -- : Verifying - actual interactions do not match expected interactions for
Incorrect requests:
GET /alligators (request headers did not match)

Diff with interaction: "a request for alligators" given "alligators exist"
Diff
--------------------------------------
Key: - is expected
+ is actual
Matching keys and values are not shown

{
"headers": {
- "Accept": "application/json"
+ "Accept": "application/xml"
}
}

Description of differences
--------------------------------------
* Expected "application/json" but got "application/xml" at $.headers.Accept


WARN -- : Incorrect requests:
GET /alligators (request headers did not match)

Diff with interaction: "a request for alligators" given "alligators exist"
Diff
--------------------------------------
Key: - is expected
+ is actual
Matching keys and values are not shown

{
"headers": {
- "Accept": "application/json"
+ "Accept": "application/xml"
}
}

Description of differences
--------------------------------------
* Expected "application/json" but got "application/xml" at $.headers.Accept


8 changes: 4 additions & 4 deletions spec/features/mock_interactions_with_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@
expect(last_response.status).to be 200

# OPTIONS request from the browser for the request under test
options '/alligators/new', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'accept', 'HTTP_ORIGIN' => 'http://localhost:1234' }
options '/alligators/new', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'accept', 'HTTP_ORIGIN' => 'http://localhost:8888' }

# Ensure it allows the browser to actually make the request
expect(last_response.status).to eq 200
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:1234'
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:8888'
expect(last_response.headers['Access-Control-Allow-Credentials']).to eq 'true'
expect(last_response.headers['Access-Control-Allow-Headers']).to include 'accept'
expect(last_response.headers['Access-Control-Allow-Methods']).to include "DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT"

# Make the request
post "/alligators/new", actual_request, { 'HTTP_ACCEPT' => 'application/json', 'HTTP_ORIGIN' => 'http://localhost:1234' }
post "/alligators/new", actual_request, { 'HTTP_ACCEPT' => 'application/json', 'HTTP_ORIGIN' => 'http://localhost:8888' }

# Ensure that the response we get back was the one we expected
# and includes the CORS header
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:1234'
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:8888'
expect(last_response.headers['Content-Type']).to eq 'application/json'
expect(JSON.parse(last_response.body)).to eq([{ 'name' => 'Mary' }])
end
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/cli_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
require 'fileutils'
require 'support/integration_spec_support'

describe "The pact-mock-service command line interface", mri_only: true do
describe "The pact-mock-service command line interface", mri_only: true, skip_windows: true do

include Pact::IntegrationTestSupport

before :all do
clear_dirs
@pid = start_server 1234, '--cors'
@pid = start_server 8888, '--cors'
end

it "responds to an OPTIONS request for a non administration request" do
response = make_options_request 1234
response = make_options_request 8888
expect(response.status).to eq 200
expect(response.headers['Access-Control-Allow-Headers']).to_not be nil
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/cli_monkeypatch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'support/integration_spec_support'
require 'find_a_port'

describe "The pact-mock-service command line interface with a monkeypatch", mri_only: true do
describe "The pact-mock-service command line interface with a monkeypatch", mri_only: true, skip_windows: true do

include Pact::IntegrationTestSupport

Expand Down
32 changes: 16 additions & 16 deletions spec/integration/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
require 'fileutils'
require 'support/integration_spec_support'

describe "The pact-mock-service command line interface", mri_only: true do
describe "The pact-mock-service command line interface", mri_only: true, skip_windows: true do

include Pact::IntegrationTestSupport

before :all do
clear_dirs
@pid = start_server 1234, "--pact-specification-version 3.0.0"
@pid = start_server 8888, "--pact-specification-version 3.0.0"
end

it "starts up and responds with mocked responses" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.status).to eq 200

response = invoke_expected_request 1234
response = invoke_expected_request 8888
puts response.body if response.status != 200
expect(response.status).to eq 200
expect(response.body).to eq 'Hello world'

write_pact 1234
write_pact 8888
expect(response.status).to eq 200
end

it "respects headers with underscores" do
setup_interaction_with_underscored_header 1234
response = invoke_request_with_underscored_header 1234
setup_interaction_with_underscored_header 8888
response = invoke_request_with_underscored_header 8888
puts response.body unless response.status == 200
expect(response.status).to eq 200
end

it "sets the X-Pact-Mock-Service-Location header" do
response = setup_interaction 1234
expect(response.headers['X-Pact-Mock-Service-Location']).to eq 'http://0.0.0.0:1234'
response = setup_interaction 8888
expect(response.headers['X-Pact-Mock-Service-Location']).to eq 'http://0.0.0.0:8888'
end

it "writes logs to the specified log file" do
expect(File.exist?('tmp/integration.log')).to be true
end

it "writes the pact to the specified directory" do
clear_interactions 1234
setup_interaction 1234
invoke_expected_request 1234
clear_interactions 8888
setup_interaction 8888
invoke_expected_request 8888
expect(File.exist?('tmp/pacts/consumer-provider.json')).to be true
end

it "sets the pact specification version" do
clear_interactions 1234
setup_interaction 1234
invoke_expected_request 1234
clear_interactions 8888
setup_interaction 8888
invoke_expected_request 8888

write_pact 1234
write_pact 8888
expect(File.read("tmp/pacts/consumer-provider.json")).to include "3.0.0"
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/cli_ssl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'fileutils'
require 'support/integration_spec_support'

describe "The pact-mock-service command line interface, with SSL", mri_only: true, skip_travis: true do
describe "The pact-mock-service command line interface, with SSL", mri_only: true, skip_travis: true, skip_windows: true, skip_gha_linux: true do

include Pact::IntegrationTestSupport

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/cli_with_auto_pact_write_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'support/integration_spec_support'
require 'find_a_port'

describe "The pact-mock-service command line interface", mri_only: true do
describe "The pact-mock-service command line interface", mri_only: true, skip_windows: true do

include Pact::IntegrationTestSupport

Expand Down
8 changes: 4 additions & 4 deletions spec/integration/control_server_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ def mock_service_headers
end
end

describe "The pact-mock-service control server command line interface", mri_only: true do
describe "The pact-mock-service control server command line interface", mri_only: true, skip_windows: true do

include Pact::ControlServerTestSupport

before :all do
clear_dirs
@pid = start_control 1234, "--pact-specification-version 3"
@pid = start_control 8888, "--pact-specification-version 3"
end

it "starts up and responds with mocked responses" do
response = setup_interaction 1234
response = setup_interaction 8888
puts response.body unless response.status == 200
expect(response.status).to eq 200
mock_service_port = URI(response.headers['X-Pact-Mock-Service-Location']).port
expect(mock_service_port).to_not eq 1234
expect(mock_service_port).to_not eq 8888

response = invoke_expected_request mock_service_port
expect(response.status).to eq 200
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/control_server_with_cors_cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'fileutils'
require 'support/integration_spec_support'

describe "The pact-mock-service control server command line interface", mri_only: true do
describe "The pact-mock-service control server command line interface", mri_only: true, skip_windows: true do

include Pact::ControlServerTestSupport

before :all do
clear_dirs
@pid = start_control 1234, '--cors'
@pid = start_control 8888, '--cors'
end

it "responds to an OPTIONS request for a non administration request" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.status).to eq 200
mock_service_port = URI(response.headers['X-Pact-Mock-Service-Location']).port

Expand Down
8 changes: 4 additions & 4 deletions spec/integration/control_server_with_ssl_cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
require 'fileutils'
require 'support/integration_spec_support'

describe "The pact-mock-service control server command line interface", mri_only: true do
describe "The pact-mock-service control server command line interface", mri_only: true, skip_windows: true do

include Pact::ControlServerTestSupport

before :all do
clear_dirs
@pid = start_control 1234, '--ssl'
@pid = start_control 8888, '--ssl'
end

it "sets the X-Pact-Mock-Service-Location with https" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.headers['X-Pact-Mock-Service-Location']).to start_with 'https://localhost:'
end

it "responds to an OPTIONS request for a non administration request" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.status).to eq 200
mock_service_port = URI(response.headers['X-Pact-Mock-Service-Location']).port
response = connect_via_ssl mock_service_port
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/stub_cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'support/integration_spec_support'

describe "The pact-stub-service command line interface", mri_only: true do
describe "The pact-stub-service command line interface", mri_only: true, skip_windows: true do

include Pact::IntegrationTestSupport

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/stub_cli_with_multiple_pacts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'support/integration_spec_support'
require 'find_a_port'

describe "The pact-stub-service command line interface with multiple pacts", mri_only: true do
describe "The pact-stub-service command line interface with multiple pacts", mri_only: true, skip_windows: true do

include Pact::IntegrationTestSupport

Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact/mock_service/app_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Pact::MockService
let(:options) { { pact_specification_version: '3' } }

context "for http://localhost" do
let(:url) { 'http://localhost:1234'}
let(:url) { 'http://localhost:8888'}

it "starts a mock service at the given port on localhost" do
expect_any_instance_of(AppRegistration).to receive(:spawn)
Expand All @@ -27,7 +27,7 @@ module Pact::MockService

it "registers the mock service as running on the given port" do
AppManager.instance.register_mock_service_for name, url, options
expect(AppManager.instance.app_registered_on?(1234)).to eq true
expect(AppManager.instance.app_registered_on?(8888)).to eq true
end

it "reports the metric for pact mock service started" do
Expand All @@ -50,7 +50,7 @@ module Pact::MockService
end

context "for https://" do
let(:url) { 'https://localhost:1234'}
let(:url) { 'https://localhost:8888'}

it "should throw an unsupported error" do
expect { AppManager.instance.register_mock_service_for name, url, options }.to raise_error "Currently only http is supported"
Expand Down
Loading

0 comments on commit d576b4c

Please sign in to comment.