Skip to content

Commit

Permalink
Gracefully allow spec helper to fail on older crystal (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Dec 17, 2023
1 parent 26599a7 commit 1d0105f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,13 @@ module DB
@before.call

if options
uri = URI.parse connection_string
uri.query_params.merge! URI::Params.parse(options)
connection_string_with_options = uri.to_s
{% if compare_versions(Crystal::VERSION, "1.9.0") >= 0 %}
uri = URI.parse connection_string
uri.query_params.merge! URI::Params.parse(options)
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
connection_string_with_options = connection_string
end
Expand Down Expand Up @@ -561,14 +565,16 @@ module DB
end
end
else
values.each do |prepared_statements|
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|
db_it.block.call db
nil
{% if compare_versions(Crystal::VERSION, "1.9.0") >= 0 %}
values.each do |prepared_statements|
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|
db_it.block.call db
nil
end
end
end
end
{% end %}
end
else
raise "Invalid prepared value. Allowed values are :both and :default"
Expand Down

0 comments on commit 1d0105f

Please sign in to comment.