Use issue expectation helpers in Lint::UnneededDisableDirective rule spec

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 21:05:33 +02:00
parent a69fba88bd
commit c8daaf4324

View file

@ -5,17 +5,15 @@ module Ameba::Rule::Lint
subject = UnneededDisableDirective.new subject = UnneededDisableDirective.new
it "passes if there are no comments" do it "passes if there are no comments" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
a = 1 a = 1
) CRYSTAL
subject.catch(s).should be_valid
end end
it "passes if there is disable directive" do it "passes if there is disable directive" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
a = 1 # my super var a = 1 # my super var
) CRYSTAL
subject.catch(s).should be_valid
end end
it "doesn't report if there is disable directive and it is needed" do it "doesn't report if there is disable directive and it is needed" do
@ -48,33 +46,27 @@ module Ameba::Rule::Lint
end end
it "fails if there is unneeded directive" do it "fails if there is unneeded directive" do
s = Source.new %Q( expect_issue subject, <<-CRYSTAL
# ameba:disable #{NamedRule.name} # ameba:disable #{NamedRule.name}
# ^{} error: Unnecessary disabling of #{NamedRule.name}
a = 1 a = 1
) CRYSTAL
subject.catch(s).should_not be_valid
s.issues.first.message.should eq(
"Unnecessary disabling of #{NamedRule.name}"
)
end end
it "fails if there is inline unneeded directive" do it "fails if there is inline unneeded directive" do
s = Source.new %Q(a = 1 # ameba:disable #{NamedRule.name}) expect_issue subject, <<-CRYSTAL
subject.catch(s).should_not be_valid a = 1 # ameba:disable #{NamedRule.name}
s.issues.first.message.should eq( # ^ error: Unnecessary disabling of #{NamedRule.name}
"Unnecessary disabling of #{NamedRule.name}" CRYSTAL
)
end end
it "detects mixed inline directives" do it "detects mixed inline directives" do
s = Source.new %Q( expect_issue subject, <<-CRYSTAL
# ameba:disable Rule1, Rule2 # ameba:disable Rule1, Rule2
# ^{} error: Unnecessary disabling of Rule1, Rule2
a = 1 # ameba:disable Rule3 a = 1 # ameba:disable Rule3
), "source.cr" # ^ error: Unnecessary disabling of Rule3
subject.catch(s).should_not be_valid CRYSTAL
s.issues.size.should eq 2
s.issues.first.message.should contain "Rule1, Rule2"
s.issues.last.message.should contain "Rule3"
end end
it "fails if there is disabled UnneededDisableDirective" do it "fails if there is disabled UnneededDisableDirective" do