mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add Naming/RescuedExceptionsVariableName
rule
This commit is contained in:
parent
0abb73f0b6
commit
1d76a7c71a
2 changed files with 104 additions and 0 deletions
|
@ -0,0 +1,53 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba::Rule::Naming
|
||||
subject = RescuedExceptionsVariableName.new
|
||||
|
||||
describe RescuedExceptionsVariableName do
|
||||
it "passes if exception handler variable name matches #allowed_names" do
|
||||
subject.allowed_names.each do |name|
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
def foo
|
||||
raise "foo"
|
||||
rescue #{name}
|
||||
nil
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
end
|
||||
|
||||
it "fails if exception handler variable name doesn't match #allowed_names" do
|
||||
expect_issue subject, <<-CRYSTAL
|
||||
def foo
|
||||
raise "foo"
|
||||
rescue wtf
|
||||
# ^^^^^^^^ error: Disallowed variable name, use one of these instead: 'e', 'ex', 'exception'
|
||||
nil
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
context "properties" do
|
||||
context "#allowed_names" do
|
||||
it "returns sensible defaults" do
|
||||
rule = RescuedExceptionsVariableName.new
|
||||
rule.allowed_names.should eq %w[e ex exception]
|
||||
end
|
||||
|
||||
it "allows setting custom names" do
|
||||
rule = RescuedExceptionsVariableName.new
|
||||
rule.allowed_names = %w[foo]
|
||||
|
||||
expect_issue rule, <<-CRYSTAL
|
||||
def foo
|
||||
raise "foo"
|
||||
rescue e
|
||||
# ^^^^^^ error: Disallowed variable name, use 'foo' instead
|
||||
nil
|
||||
end
|
||||
CRYSTAL
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue