Use issue expectation helpers in Lint::BadDirective rule spec

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 21:27:04 +02:00
parent 5283ae4a96
commit caeb1609c9

View file

@ -5,62 +5,42 @@ module Ameba::Rule::Lint
subject = BadDirective.new subject = BadDirective.new
it "does not report if rule is correct" do it "does not report if rule is correct" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
# ameba:disable Lint/BadDirective # ameba:disable Lint/BadDirective
) CRYSTAL
subject.catch(s).should be_valid
end end
it "reports if there is incorrect action" do it "reports if there is incorrect action" do
s = Source.new %( expect_issue subject, <<-CRYSTAL
# ameba:foo Lint/BadDirective # ameba:foo Lint/BadDirective
), "source.cr" # ^{} error: Bad action in comment directive: 'foo'. Possible values: disable, enable
subject.catch(s).should_not be_valid CRYSTAL
s.issues.size.should eq 1
issue = s.issues.first
issue.message.should eq(
"Bad action in comment directive: 'foo'. Possible values: disable, enable"
)
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq ""
end end
it "reports if there are incorrect rule names" do it "reports if there are incorrect rule names" do
s = Source.new %( expect_issue subject, <<-CRYSTAL
# ameba:enable BadRule1, BadRule2 # ameba:enable BadRule1, BadRule2
), "source.cr" # ^{} error: Such rules do not exist: BadRule1, BadRule2
subject.catch(s).should_not be_valid CRYSTAL
s.issues.size.should eq 1
issue = s.issues.first
issue.message.should eq(
"Such rules do not exist: BadRule1, BadRule2"
)
issue.location.to_s.should eq "source.cr:1:1"
issue.end_location.to_s.should eq ""
end end
it "does not report if there no action and rules at all" do it "does not report if there no action and rules at all" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
# ameba: # ameba:
) CRYSTAL
subject.catch(s).should be_valid
end end
it "does not report if there are no rules" do it "does not report if there are no rules" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
# ameba:enable # ameba:enable
# ameba:disable # ameba:disable
) CRYSTAL
subject.catch(s).should be_valid
end end
it "does not report if there are group names in the directive" do it "does not report if there are group names in the directive" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
# ameba:disable Style Performance # ameba:disable Style Performance
) CRYSTAL
subject.catch(s).should be_valid
end end
end end
end end