Skip to content

Commit c28588e

Browse files
test: Fix Sinatra Tests (#1253)
* test: Fix Sinatra Tests Sinatra 4.1 now includes a stricter host authorization check by default, which caused our tests to fail. The host authorization is not enforced in development and test mode so this PR sets the Sinatra environment to run in `test` mode. See: sinatra/sinatra#2053 fixes #1252 * squash: update appraisals --------- Co-authored-by: Kayla Reopelle <[email protected]>
1 parent acac4fd commit c28588e

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

instrumentation/sinatra/Appraisals

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
appraise 'sinatra-4.x' do
8-
gem 'sinatra', '~> 4.0'
9-
end
10-
11-
appraise 'sinatra-3.x' do
12-
gem 'sinatra', '~> 3.0'
13-
end
14-
15-
appraise 'sinatra-2.x' do
16-
gem 'sinatra', '~> 2.1'
7+
%w[4.1 3.0 2.1].each do |version|
8+
appraise "sinatra-#{version}" do
9+
gem 'sinatra', "~> #{version}"
10+
end
1711
end
1812

1913
appraise 'sinatra-latest' do

instrumentation/sinatra/test/opentelemetry/instrumentation/sinatra_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CustomError < StandardError; end
1717

1818
let(:app_one) do
1919
Class.new(Sinatra::Application) do
20+
set :raise_errors, false
2021
get '/endpoint' do
2122
'1'
2223
end
@@ -41,6 +42,7 @@ class CustomError < StandardError; end
4142

4243
let(:app_two) do
4344
Class.new(Sinatra::Application) do
45+
set :raise_errors, false
4446
get '/endpoint' do
4547
'2'
4648
end
@@ -165,7 +167,8 @@ class CustomError < StandardError; end
165167
'http.method' => 'GET',
166168
'http.route' => '/error',
167169
'http.scheme' => 'http',
168-
'http.target' => '/error'
170+
'http.target' => '/error',
171+
'http.status_code' => 500
169172
)
170173
_(exporter.finished_spans.flat_map(&:events).map(&:name)).must_equal(['exception'])
171174
end

instrumentation/sinatra/test/test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright The OpenTelemetry Authors
44
#
55
# SPDX-License-Identifier: Apache-2.0
6+
ENV['APP_ENV'] = 'test'
67

78
require 'bundler/setup'
89
Bundler.require(:default, :development, :test)

0 commit comments

Comments
 (0)