diff --git a/spec/ameba/rule/performance/map_instead_of_block_spec.cr b/spec/ameba/rule/performance/map_instead_of_block_spec.cr index d51f8556..95cfd901 100644 --- a/spec/ameba/rule/performance/map_instead_of_block_spec.cr +++ b/spec/ameba/rule/performance/map_instead_of_block_spec.cr @@ -5,47 +5,44 @@ module Ameba::Rule::Performance describe MapInsteadOfBlock do it "passes if there is no potential performance improvements" do - source = Source.new %( + expect_no_issues subject, <<-CRYSTAL (1..3).sum(&.*(2)) (1..3).product(&.*(2)) - ) - subject.catch(source).should be_valid + CRYSTAL end it "reports if there is map followed by sum without a block" do - source = Source.new %( + expect_issue subject, <<-CRYSTAL (1..3).map(&.to_u64).sum - ) - subject.catch(source).should_not be_valid + # ^^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum` + CRYSTAL end it "does not report if source is a spec" do - source = Source.new %( + expect_no_issues subject, path: "source_spec.cr", code: <<-CRYSTAL (1..3).map(&.to_s).join - ), "source_spec.cr" - subject.catch(source).should be_valid + CRYSTAL end it "reports if there is map followed by sum without a block (with argument)" do - source = Source.new %( + expect_issue subject, <<-CRYSTAL (1..3).map(&.to_u64).sum(0) - ) - subject.catch(source).should_not be_valid + # ^^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum` + CRYSTAL end it "reports if there is map followed by sum with a block" do - source = Source.new %( + expect_issue subject, <<-CRYSTAL (1..3).map(&.to_u64).sum(&.itself) - ) - subject.catch(source).should_not be_valid + # ^^^^^^^^^^^^^^^^^^ error: Use `sum {...}` instead of `map {...}.sum` + CRYSTAL end context "macro" do it "doesn't report in macro scope" do - source = Source.new %( + expect_no_issues subject, <<-CRYSTAL {{ [1, 2, 3].map(&.to_u64).sum }} - ) - subject.catch(source).should be_valid + CRYSTAL end end