shard-ameba/spec/ameba/base_spec.cr

91 lines
2.4 KiB
Crystal
Raw Normal View History

2017-11-22 06:44:29 +00:00
require "../spec_helper"
module Ameba::Rule
describe Base do
2018-01-25 09:50:11 +00:00
context ".rules" do
it "returns a list of all rules" do
rules = Rule.rules
rules.should_not be_nil
rules.should contain DummyRule
end
it "contains rules across all the available groups" do
Rule.rules.map(&.group_name).uniq!.reject!(&.empty?).sort.should eq %w(
Ameba
Layout
Lint
Metrics
Performance
Style
)
end
2018-01-25 09:50:11 +00:00
end
2017-11-22 06:44:29 +00:00
context "properties" do
subject = DummyRule.new
it "is enabled by default" do
2022-11-22 18:46:38 +00:00
subject.enabled?.should be_true
2017-11-22 06:44:29 +00:00
end
it "has a description property" do
subject.description.should_not be_nil
end
2017-11-30 21:50:07 +00:00
2022-11-22 18:53:27 +00:00
it "has a dummy? property" do
subject.dummy?.should be_true
end
2017-11-30 21:50:07 +00:00
it "has excluded property" do
subject.excluded.should be_nil
end
2017-11-22 06:44:29 +00:00
end
2017-12-18 11:06:19 +00:00
describe "#excluded?" do
it "returns false if a rule does no have a list of excluded source" do
DummyRule.new.excluded?(Source.new "", "source.cr").should_not be_true
end
it "returns false if source is not excluded from this rule" do
rule = DummyRule.new
rule.excluded = %w(some_source.cr)
rule.excluded?(Source.new "", "another_source.cr").should_not be_true
end
it "returns true if source is excluded from this rule" do
rule = DummyRule.new
rule.excluded = %w(source.cr)
rule.excluded?(Source.new "", "source.cr").should be_true
end
2018-05-29 10:19:00 +00:00
it "returns true if source matches the wildcard" do
2017-12-18 11:06:19 +00:00
rule = DummyRule.new
rule.excluded = %w(**/*.cr)
2018-05-29 10:19:00 +00:00
rule.excluded?(Source.new "", __FILE__).should be_true
2017-12-18 11:06:19 +00:00
end
it "returns false if source does not match the wildcard" do
rule = DummyRule.new
rule.excluded = %w(*_spec.cr)
rule.excluded?(Source.new "", "source.cr").should be_false
end
end
2018-12-08 20:52:32 +00:00
describe ".parsed_doc" do
it "returns the parsed rule doc" do
DummyRule.parsed_doc.should eq "Dummy Rule which does nothing."
end
end
describe "#==" do
it "returns true if rule has the same name" do
DummyRule.new.should eq(DummyRule.new)
end
it "returns false if rule has a different name" do
2020-06-15 11:19:23 +00:00
DummyRule.new.should_not eq(ScopeRule.new)
end
end
2017-11-22 06:44:29 +00:00
end
end