Gracefully allow spec helper to fail on older crystal (#202)

This commit is contained in:
Brian J. Cardiff 2023-12-17 20:03:45 -03:00 committed by GitHub
parent 26599a740f
commit 1d0105ffeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -398,9 +398,13 @@ module DB
@before.call @before.call
if options if options
{% if compare_versions(Crystal::VERSION, "1.9.0") >= 0 %}
uri = URI.parse connection_string uri = URI.parse connection_string
uri.query_params.merge! URI::Params.parse(options) uri.query_params.merge! URI::Params.parse(options)
connection_string_with_options = uri.to_s connection_string_with_options = uri.to_s
{% else %}
raise "Crystal 1.9.0 or greater is required to run with_db with options"
{% end %}
else else
connection_string_with_options = connection_string connection_string_with_options = connection_string
end end
@ -561,6 +565,7 @@ module DB
end end
end end
else else
{% if compare_versions(Crystal::VERSION, "1.9.0") >= 0 %}
values.each do |prepared_statements| values.each do |prepared_statements|
it("#{db_it.description} (prepared_statements=#{prepared_statements})", db_it.file, db_it.line, db_it.end_line) do it("#{db_it.description} (prepared_statements=#{prepared_statements})", db_it.file, db_it.line, db_it.end_line) do
ctx.with_db "prepared_statements=#{prepared_statements}" do |db| ctx.with_db "prepared_statements=#{prepared_statements}" do |db|
@ -569,6 +574,7 @@ module DB
end end
end end
end end
{% end %}
end end
else else
raise "Invalid prepared value. Allowed values are :both and :default" raise "Invalid prepared value. Allowed values are :both and :default"