mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Specs cleanup
This commit is contained in:
parent
e6ebca7a5b
commit
8112dddc8f
24 changed files with 267 additions and 251 deletions
|
@ -45,6 +45,7 @@ module Ameba::Rule::Style
|
|||
it "allows to configure filter_names" do
|
||||
rule = IsAFilter.new
|
||||
rule.filter_names = %w(select)
|
||||
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, nil].reject(&.nil?)
|
||||
CRYSTAL
|
||||
|
|
|
@ -51,7 +51,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "allows to configure assignments" do
|
||||
rule = Rule::Style::ParenthesesAroundCondition.new
|
||||
rule = ParenthesesAroundCondition.new
|
||||
rule.exclude_ternary = false
|
||||
|
||||
expect_issue rule, <<-CRYSTAL
|
||||
|
@ -98,7 +98,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "allows to configure assignments" do
|
||||
rule = Rule::Style::ParenthesesAroundCondition.new
|
||||
rule = ParenthesesAroundCondition.new
|
||||
rule.allow_safe_assignment = true
|
||||
|
||||
expect_issue rule, <<-CRYSTAL
|
||||
|
|
|
@ -211,7 +211,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "allows to configure multi next statements" do
|
||||
rule = Rule::Style::RedundantNext.new
|
||||
rule = RedundantNext.new
|
||||
rule.allow_multi_next = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
block do |a, b|
|
||||
|
@ -238,7 +238,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "allows to configure empty next statements" do
|
||||
rule = Rule::Style::RedundantNext.new
|
||||
rule = RedundantNext.new
|
||||
rule.allow_empty_next = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
block do
|
||||
|
|
|
@ -294,7 +294,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "allows to configure multi returns" do
|
||||
rule = Rule::Style::RedundantReturn.new
|
||||
rule = RedundantReturn.new
|
||||
rule.allow_multi_return = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
def method(a, b)
|
||||
|
@ -321,7 +321,7 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "allows to configure empty returns" do
|
||||
rule = Rule::Style::RedundantReturn.new
|
||||
rule = RedundantReturn.new
|
||||
rule.allow_empty_return = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
def method
|
||||
|
|
|
@ -64,10 +64,12 @@ module Ameba::Rule::Style
|
|||
context "properties" do
|
||||
it "#exclude_calls_with_block" do
|
||||
rule = VerboseBlock.new
|
||||
|
||||
rule.exclude_calls_with_block = true
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
(1..3).in_groups_of(1) { |i| i.map(&.to_s) }
|
||||
CRYSTAL
|
||||
|
||||
rule.exclude_calls_with_block = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
(1..3).in_groups_of(1) { |i| i.map(&.to_s) }
|
||||
|
@ -81,12 +83,14 @@ module Ameba::Rule::Style
|
|||
|
||||
it "#exclude_multiple_line_blocks" do
|
||||
rule = VerboseBlock.new
|
||||
|
||||
rule.exclude_multiple_line_blocks = true
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
(1..3).any? do |i|
|
||||
i.odd?
|
||||
end
|
||||
CRYSTAL
|
||||
|
||||
rule.exclude_multiple_line_blocks = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
(1..3).any? do |i|
|
||||
|
@ -102,12 +106,14 @@ module Ameba::Rule::Style
|
|||
|
||||
it "#exclude_prefix_operators" do
|
||||
rule = VerboseBlock.new
|
||||
|
||||
rule.exclude_prefix_operators = true
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
(1..3).sum { |i| +i }
|
||||
(1..3).sum { |i| -i }
|
||||
(1..3).sum { |i| ~i }
|
||||
CRYSTAL
|
||||
|
||||
rule.exclude_prefix_operators = false
|
||||
rule.exclude_operators = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
|
@ -128,10 +134,12 @@ module Ameba::Rule::Style
|
|||
|
||||
it "#exclude_operators" do
|
||||
rule = VerboseBlock.new
|
||||
|
||||
rule.exclude_operators = true
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
(1..3).sum { |i| i * 2 }
|
||||
CRYSTAL
|
||||
|
||||
rule.exclude_operators = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
(1..3).sum { |i| i * 2 }
|
||||
|
@ -145,10 +153,12 @@ module Ameba::Rule::Style
|
|||
|
||||
it "#exclude_setters" do
|
||||
rule = VerboseBlock.new
|
||||
|
||||
rule.exclude_setters = true
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
Char::Reader.new("abc").tap { |reader| reader.pos = 0 }
|
||||
CRYSTAL
|
||||
|
||||
rule.exclude_setters = false
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
Char::Reader.new("abc").tap { |reader| reader.pos = 0 }
|
||||
|
@ -163,12 +173,14 @@ module Ameba::Rule::Style
|
|||
it "#max_line_length" do
|
||||
rule = VerboseBlock.new
|
||||
rule.exclude_multiple_line_blocks = false
|
||||
|
||||
rule.max_line_length = 60
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
(1..3).tap &.tap &.tap &.tap &.tap &.tap &.tap do |i|
|
||||
i.to_s.reverse.strip.blank?
|
||||
end
|
||||
CRYSTAL
|
||||
|
||||
rule.max_line_length = nil
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
(1..3).tap &.tap &.tap &.tap &.tap &.tap &.tap do |i|
|
||||
|
@ -184,10 +196,12 @@ module Ameba::Rule::Style
|
|||
|
||||
it "#max_length" do
|
||||
rule = VerboseBlock.new
|
||||
|
||||
rule.max_length = 30
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
(1..3).tap { |i| i.to_s.split.reverse.join.strip.blank? }
|
||||
CRYSTAL
|
||||
|
||||
rule.max_length = nil
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
(1..3).tap { |i| i.to_s.split.reverse.join.strip.blank? }
|
||||
|
@ -216,6 +230,7 @@ module Ameba::Rule::Style
|
|||
it "reports call args and named_args" do
|
||||
rule = VerboseBlock.new
|
||||
rule.exclude_operators = false
|
||||
|
||||
source = expect_issue rule, <<-CRYSTAL
|
||||
(1..3).map { |i| i.to_s[start: 0.to_i64, count: 3]? }
|
||||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: [...] `map(&.to_s.[start: 0.to_i64, count: 3]?)`
|
||||
|
@ -260,9 +275,9 @@ module Ameba::Rule::Style
|
|||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
source = Source.new path: "source.cr", code: %(
|
||||
source = Source.new path: "source.cr", code: <<-CRYSTAL
|
||||
(1..3).any? { |i| i.odd? }
|
||||
)
|
||||
CRYSTAL
|
||||
subject.catch(source).should_not be_valid
|
||||
source.issues.size.should eq 1
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue