2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-11-16 14:31:32 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Lint
|
2017-11-16 14:31:32 +00:00
|
|
|
describe EmptyEnsure do
|
|
|
|
subject = EmptyEnsure.new
|
|
|
|
|
|
|
|
it "passes if there is no empty ensure blocks" do
|
2022-04-03 21:56:11 +00:00
|
|
|
expect_no_issues subject, <<-CRYSTAL
|
2017-11-16 14:31:32 +00:00
|
|
|
def some_method
|
|
|
|
do_some_stuff
|
|
|
|
ensure
|
|
|
|
do_something_else
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
do_some_stuff
|
|
|
|
ensure
|
|
|
|
do_something_else
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_with_rescue
|
|
|
|
rescue
|
|
|
|
ensure
|
|
|
|
nil
|
|
|
|
end
|
2022-04-03 21:56:11 +00:00
|
|
|
CRYSTAL
|
2017-11-16 14:31:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is an empty ensure in method" do
|
2022-04-03 21:56:11 +00:00
|
|
|
expect_issue subject, <<-CRYSTAL
|
2017-11-16 14:31:32 +00:00
|
|
|
def method
|
|
|
|
do_some_stuff
|
|
|
|
ensure
|
2022-04-03 21:56:11 +00:00
|
|
|
# ^^^^^^ error: Empty `ensure` block detected
|
2017-11-16 14:31:32 +00:00
|
|
|
end
|
2022-04-03 21:56:11 +00:00
|
|
|
CRYSTAL
|
2017-11-16 14:31:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is an empty ensure in a block" do
|
2022-04-03 21:56:11 +00:00
|
|
|
expect_issue subject, <<-CRYSTAL
|
2017-11-16 14:31:32 +00:00
|
|
|
begin
|
|
|
|
do_some_stuff
|
|
|
|
rescue
|
|
|
|
do_some_other_stuff
|
|
|
|
ensure
|
2022-04-03 21:56:11 +00:00
|
|
|
# ^^^^^^ error: Empty `ensure` block detected
|
|
|
|
# nothing here
|
2017-11-16 14:31:32 +00:00
|
|
|
end
|
2022-04-03 21:56:11 +00:00
|
|
|
CRYSTAL
|
2017-11-16 14:31:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|