Add conditional check using semantic version

This commit is contained in:
Vitalii Elenhaupt 2022-04-03 20:16:00 +03:00
parent 2f29999106
commit 1f4dda1c4a
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
2 changed files with 12 additions and 2 deletions

View file

@ -1,4 +1,5 @@
require "../../../spec_helper"
require "semantic_version"
module Ameba::Rule::Lint
describe EmptyEnsure do
@ -63,7 +64,11 @@ module Ameba::Rule::Lint
issue.rule.should_not be_nil
# TODO: refactor this in next release
# Crystal 1.4 changes the start location of Crystal::ExceptionHandler
# issue.location.to_s.should eq "source.cr:2:3"
if SemanticVersion.parse(Crystal::VERSION) <= SemanticVersion.parse("1.3.2")
issue.location.to_s.should eq "source.cr:2:3"
else
issue.location.to_s.should eq "source.cr:1:1"
end
issue.end_location.to_s.should eq "source.cr:6:3"
issue.message.should eq "Empty `ensure` block detected"
end

View file

@ -1,4 +1,5 @@
require "../../../spec_helper"
require "semantic_version"
private def check_shadowed(source, exceptions)
s = Ameba::Source.new source
@ -168,7 +169,11 @@ module Ameba::Rule::Lint
issue.rule.should_not be_nil
# TODO: refactor this in next release
# Crystal 1.4 changes the start location of Crystal::ExceptionHandler
# issue.location.to_s.should eq "source.cr:2:3"
if SemanticVersion.parse(Crystal::VERSION) <= SemanticVersion.parse("1.3.2")
issue.location.to_s.should eq "source.cr:2:3"
else
issue.location.to_s.should eq "source.cr:1:1"
end
issue.end_location.to_s.should eq "source.cr:4:3"
issue.message.should eq(
"Exception handler has shadowed exceptions: IndexError"