diff --git a/test/json_schema_test_suite_test.rb b/test/json_schema_test_suite_test.rb index 26dedbef..f68d1a60 100644 --- a/test/json_schema_test_suite_test.rb +++ b/test/json_schema_test_suite_test.rb @@ -45,7 +45,7 @@ class JSONSchemaTestSuiteTest < Minitest::Test path = Pathname.new(__dir__).join('..', 'JSON-Schema-Test-Suite', 'remotes', uri.path.gsub(/\A\//, '')) JSON.parse(path.read) else - JSON.parse(Net::HTTP.get(uri)) + JSON.parse(fetch(uri)) end end diff --git a/test/json_schemer_test.rb b/test/json_schemer_test.rb index 1bde86f3..192f8b8e 100644 --- a/test/json_schemer_test.rb +++ b/test/json_schemer_test.rb @@ -422,7 +422,7 @@ def test_published_meta_schemas JSONSchemer::OpenAPI30::Document::SCHEMA ].each do |meta_schema| id = meta_schema.key?('$id') ? meta_schema.fetch('$id') : meta_schema.fetch('id') - assert_equal(meta_schema, JSON.parse(Net::HTTP.get(URI(id)))) + assert_equal(meta_schema, JSON.parse(fetch(id))) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 60544faa..8a576cb2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,3 +12,17 @@ require "json_schemer" require "minitest/autorun" + +def fetch(location, limit = 10) + raise if limit.zero? + uri = URI(location) + response = Net::HTTP.get_response(uri) + case response + when Net::HTTPSuccess + response.body + when Net::HTTPRedirection + fetch(URI.join(uri, response['Location']), limit - 1) + else + response.value.body + end +end