diff --git a/spec/ameba/cli/cmd_spec.cr b/spec/ameba/cli/cmd_spec.cr index c02068482..2be16982d 100644 --- a/spec/ameba/cli/cmd_spec.cr +++ b/spec/ameba/cli/cmd_spec.cr @@ -32,6 +32,13 @@ module Ameba::Cli end end + %w[-u --up-to-version].each do |flag| + it "accepts #{flag} flag" do + c = Cli.parse_args [flag, "1.5.0"] + c.version.should eq "1.5.0" + end + end + it "accepts --only flag" do c = Cli.parse_args ["--only", "RULE1,RULE2"] c.only.should eq %w[RULE1 RULE2] diff --git a/spec/ameba/config_spec.cr b/spec/ameba/config_spec.cr index 678da23ba..e25469c55 100644 --- a/spec/ameba/config_spec.cr +++ b/spec/ameba/config_spec.cr @@ -80,6 +80,7 @@ module Ameba it "loads custom config" do config = Config.load config_sample config.should_not be_nil + config.version.should_not be_nil config.globs.should_not be_nil config.formatter.should_not be_nil end @@ -93,6 +94,7 @@ module Ameba it "loads default config" do config = Config.load config.should_not be_nil + config.version.should be_nil config.globs.should_not be_nil config.formatter.should_not be_nil end @@ -169,6 +171,31 @@ module Ameba end end + describe "#version, version=" do + config = Config.load config_sample + version = SemanticVersion.parse("1.5.0") + + it "contains default version" do + config.version.should_not be_nil + end + + it "allows to set version" do + config.version = version + config.version.should eq version + end + + it "allows to set version using a string" do + config.version = version.to_s + config.version.should eq version + end + + it "raises an error if version is not valid" do + expect_raises(Exception) do + config.version = "foo" + end + end + end + describe "#update_rule" do config = Config.load config_sample diff --git a/spec/ameba/runner_spec.cr b/spec/ameba/runner_spec.cr index f1fc904cf..17aa97c8c 100644 --- a/spec/ameba/runner_spec.cr +++ b/spec/ameba/runner_spec.cr @@ -6,6 +6,7 @@ module Ameba config.formatter = formatter config.globs = files + config.update_rule VersionedRule.rule_name, enabled: false config.update_rule ErrorRule.rule_name, enabled: false config.update_rule PerfRule.rule_name, enabled: false config.update_rule AtoAA.rule_name, enabled: false @@ -48,6 +49,20 @@ module Ameba formatter.finished_source.should_not be_nil end + it "checks accordingly to the rule #since_version" do + rules = [VersionedRule.new] of Rule::Base + source = Source.new "", "source.cr" + + v1_0_0 = SemanticVersion.parse("1.0.0") + Runner.new(rules, [source], formatter, default_severity, false, v1_0_0).run.success?.should be_true + + v1_5_0 = SemanticVersion.parse("1.5.0") + Runner.new(rules, [source], formatter, default_severity, false, v1_5_0).run.success?.should be_false + + v1_10_0 = SemanticVersion.parse("1.10.0") + Runner.new(rules, [source], formatter, default_severity, false, v1_10_0).run.success?.should be_false + end + it "skips rule check if source is excluded" do path = "source.cr" source = Source.new "", path diff --git a/spec/fixtures/config.yml b/spec/fixtures/config.yml index c5394b90f..07efce09a 100644 --- a/spec/fixtures/config.yml +++ b/spec/fixtures/config.yml @@ -1,2 +1,4 @@ +version: "1.5.0" + Lint/ComparisonToBoolean: Enabled: true diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 04dfa74cf..b246e23f6 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -24,6 +24,17 @@ module Ameba end end + class VersionedRule < Rule::Base + properties do + since_version "1.5.0" + description "Rule with a custom version." + end + + def test(source) + issue_for({1, 1}, "This rule always adds an error") + end + end + # Rule extended description class ErrorRule < Rule::Base properties do