Skip to content

Commit 62e9725

Browse files
RUBY-2859 Add GH Actions setup for ruby 3.1 (#2398)
Co-authored-by: shields <[email protected]> Co-authored-by: Dmitry Rybakov <[email protected]>
1 parent bea529a commit 62e9725

File tree

15 files changed

+49
-16
lines changed

15 files changed

+49
-16
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os: [ ubuntu-latest ]
15-
ruby: ["2.5", "2.6", "2.7", "3.0"]
15+
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1"]
1616
mongodb: ["3.6", "4.4", "5.0"]
1717
topology: [replica_set, sharded_cluster]
1818
include:
@@ -40,6 +40,10 @@ jobs:
4040
ruby: "3.0"
4141
mongodb: "5.0"
4242
topology: server
43+
- os: ubuntu-latest
44+
ruby: "3.1"
45+
mongodb: "5.0"
46+
topology: server
4347
- os: ubuntu-18.04
4448
ruby: "2.5"
4549
mongodb: "3.6"

spec/runners/auth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Spec
4848
attr_reader :tests
4949

5050
def initialize(test_path)
51-
@spec = YAML.load(File.read(test_path))
51+
@spec = ::Utils.load_spec_yaml_file(test_path)
5252
@description = File.basename(test_path)
5353
end
5454

spec/runners/change_streams/spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Spec
3232
#
3333
# @since 2.6.0
3434
def initialize(test_path)
35-
@spec = YAML.load(File.read(test_path))
35+
@spec = ::Utils.load_spec_yaml_file(test_path)
3636
@description = File.basename(test_path)
3737
@spec_tests = @spec['tests']
3838
@collection_name = @spec['collection_name']

spec/runners/cmap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Spec
4040
#
4141
# @param [ String ] test_path The path to the file.
4242
def initialize(test_path)
43-
@test = YAML.load(File.read(test_path))
43+
@test = ::Utils.load_spec_yaml_file(test_path)
4444

4545
@description = @test['description']
4646
@pool_options = ::Utils.snakeize_hash(process_options(@test['poolOptions']))

spec/runners/command_monitoring.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class Spec
204204
#
205205
# @since 2.1.0
206206
def initialize(test_path)
207-
@spec = YAML.load(File.read(test_path))
207+
@spec = ::Utils.load_spec_yaml_file(test_path)
208208
@data = @spec['data']
209209
@tests = @spec['tests']
210210
end

spec/runners/connection_string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Spec
100100
#
101101
# @since 2.0.0
102102
def initialize(test_path)
103-
@spec = YAML.load(File.read(test_path))
103+
@spec = ::Utils.load_spec_yaml_file(test_path)
104104
@description = File.basename(test_path)
105105
end
106106

spec/runners/crud/spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class Spec
1212
#
1313
# @since 2.0.0
1414
def initialize(test_path)
15-
contents = File.read(test_path)
16-
17-
@spec = YAML.load(contents)
15+
@spec = ::Utils.load_spec_yaml_file(test_path)
1816
@description = File.basename(test_path)
1917
@data = BSON::ExtJSON.parse_obj(@spec['data'])
2018
@tests = @spec['tests']

spec/runners/gridfs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Spec
100100
#
101101
# @since 2.1.0
102102
def initialize(test_path)
103-
@spec = YAML.load(File.read(test_path))
103+
@spec = ::Utils.load_spec_yaml_file(test_path)
104104
@description = File.basename(test_path)
105105
@data = @spec['data']
106106
end

spec/runners/read_write_concern_document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Spec
1313
#
1414
# @since 2.0.0
1515
def initialize(test_path)
16-
@spec = YAML.load(File.read(test_path))
16+
@spec = ::Utils.load_spec_yaml_file(test_path)
1717
@description = File.basename(test_path)
1818
end
1919

spec/runners/sdam.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Spec
7777
#
7878
# @since 2.0.0
7979
def initialize(test_path)
80-
@test = YAML.load(File.read(test_path))
80+
@test = ::Utils.load_spec_yaml_file(test_path)
8181
@description = @test['description']
8282
@uri_string = @test['uri']
8383
@uri = URI.new(uri_string)

spec/runners/server_selection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Spec
6464
#
6565
# @since 2.0.0
6666
def initialize(test_path)
67-
@test = YAML.load(File.read(test_path))
67+
@test = ::Utils.load_spec_yaml_file(test_path)
6868
@description = "#{@test['topology_description']['type']}: #{File.basename(test_path)}"
6969
@heartbeat_frequency = @test['heartbeatFrequencyMS'] / 1000 if @test['heartbeatFrequencyMS']
7070
@read_preference = @test['read_preference']

spec/runners/server_selection_rtt.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Spec
2828
#
2929
# @since 2.0.0
3030
def initialize(test_path)
31-
@test = YAML.load(File.read(test_path))
31+
@test = ::Utils.load_spec_yaml_file(test_path)
3232
@description = "#{File.basename(test_path)}: avg_rtt_ms: #{@test['avg_rtt_ms']}, new_rtt_ms: #{@test['new_rtt_ms']}," +
3333
" new_avg_rtt: #{@test['new_avg_rtt']}"
3434
@average_rtt = @test['avg_rtt_ms'] == 'NULL' ? nil : @test['avg_rtt_ms'].to_f / 1000

spec/runners/unified/test_group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Unified
66
class TestGroup
77
def initialize(path, **opts)
88
if String === path
9-
data = YAML.load(File.read(path))
9+
data = ::Utils.load_spec_yaml_file(path)
1010
else
1111
data = path
1212
end

spec/spec_tests/seed_list_discovery_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
SEED_LIST_DISCOVERY_TESTS.each do |test_path|
1717

18-
spec = YAML.load(File.read(test_path))
18+
spec = ::Utils.load_spec_yaml_file(test_path)
1919

2020
test = Mongo::ConnectionString::Test.new(spec)
2121

spec/support/utils.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,35 @@ def match_with_type?(expected, actual)
613613
end
614614
end
615615
end
616+
617+
module_function def load_spec_yaml_file(path)
618+
permitted_classes = [
619+
BigDecimal,
620+
Date,
621+
Time,
622+
Range,
623+
Regexp,
624+
Symbol,
625+
BSON::Binary,
626+
BSON::Code,
627+
BSON::CodeWithScope,
628+
BSON::DbPointer,
629+
BSON::Decimal128,
630+
BSON::Int32,
631+
BSON::Int64,
632+
BSON::MaxKey,
633+
BSON::MinKey,
634+
BSON::ObjectId,
635+
BSON::Regexp::Raw,
636+
BSON::Symbol::Raw,
637+
BSON::Timestamp,
638+
BSON::Undefined,
639+
]
640+
if RUBY_VERSION.start_with?("2.5")
641+
YAML.safe_load(File.read(path), permitted_classes, [], true)
642+
else
643+
# Here we have Ruby 2.6+ that supports the new syntax of `safe_load``.
644+
YAML.safe_load(File.read(path), permitted_classes: permitted_classes, aliases: true)
645+
end
646+
end
616647
end

0 commit comments

Comments
 (0)