shard-ameba/spec/ameba/rule/lint/duplicated_require_spec.cr
fn ⌃ ⌥ 7b437fbd2f
Remove normalize parameter from expect_issue (#249)
* Add `normalize` parameter to `expect_correction`

* Convert Style/IsAFilter spec

* Revert "Add `normalize` parameter to `expect_correction`"

This reverts commit 4b67e4b900.

* Remove `normalize` parameter from `expect_issue`

* Require indentation if multiple issues on a single line

* Update `Style/IsAFilter` spec

* Update `ExpectIssue` documentation

* Add missing `expect_no_corrections`

* Use carets and space with issues at column 1 or 2

* Update `expect_issue` docs
2021-11-06 15:15:19 +02:00

49 lines
1.3 KiB
Crystal

require "../../../spec_helper"
module Ameba::Rule::Lint
subject = DuplicatedRequire.new
describe DuplicatedRequire do
it "passes if there are no duplicated requires" do
expect_no_issues subject, <<-CRYSTAL
require "math"
require "big"
require "big/big_decimal"
CRYSTAL
end
it "reports if there are a duplicated requires" do
source = expect_issue subject, <<-CRYSTAL
require "big"
require "math"
require "big"
# ^{} error: Duplicated require of `big`
CRYSTAL
expect_no_corrections source
end
it "reports rule, pos and message" do
source = Source.new %(
require "./thing"
require "./thing"
require "./another_thing"
require "./another_thing"
), "source.cr"
subject.catch(source).should_not be_valid
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:2:1"
issue.end_location.to_s.should eq ""
issue.message.should eq "Duplicated require of `./thing`"
issue = source.issues.last
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:4:1"
issue.end_location.to_s.should eq ""
issue.message.should eq "Duplicated require of `./another_thing`"
end
end
end