shard-ameba/spec/ameba/rule/lint/empty_ensure_spec.cr

53 lines
1 KiB
Crystal
Raw Normal View History

require "../../../spec_helper"
2017-11-16 14:31:32 +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
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
CRYSTAL
2017-11-16 14:31:32 +00:00
end
it "fails if there is an empty ensure in method" do
expect_issue subject, <<-CRYSTAL
2017-11-16 14:31:32 +00:00
def method
do_some_stuff
ensure
# ^^^^^^ error: Empty `ensure` block detected
2017-11-16 14:31:32 +00:00
end
CRYSTAL
2017-11-16 14:31:32 +00:00
end
it "fails if there is an empty ensure in a block" do
expect_issue subject, <<-CRYSTAL
2017-11-16 14:31:32 +00:00
begin
do_some_stuff
rescue
do_some_other_stuff
ensure
# ^^^^^^ error: Empty `ensure` block detected
# nothing here
2017-11-16 14:31:32 +00:00
end
CRYSTAL
2017-11-16 14:31:32 +00:00
end
end
end