shard-ameba/spec/ameba/base_spec.cr

72 lines
1.9 KiB
Crystal
Raw Normal View History

2017-11-22 06:44:29 +00:00
require "../spec_helper"
module Ameba::Rule
struct NoProperties < Rule::Base
def test(source)
end
end
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
rules.should contain NoProperties
end
end
2017-11-22 06:44:29 +00:00
context "properties" do
subject = DummyRule.new
it "is enabled by default" do
subject.enabled.should be_true
end
it "has a description property" do
subject.description.should_not be_nil
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
describe "when a rule does not have defined properties" do
it "is enabled by default" do
NoProperties.new.enabled.should be_true
end
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
2017-11-22 06:44:29 +00:00
end
end