Skip to content

Commit

Permalink
Batch replace should be_valid with expect_no_issues
Browse files Browse the repository at this point in the history
  • Loading branch information
FnControlOption committed Oct 21, 2021
1 parent b63f95c commit 4ec325c
Show file tree
Hide file tree
Showing 41 changed files with 234 additions and 463 deletions.
3 changes: 1 addition & 2 deletions spec/ameba/rule/lint/empty_ensure_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Ameba::Rule::Lint
subject = EmptyEnsure.new

it "passes if there is no empty ensure blocks" do
s = Source.new %(
expect_no_issues subject, %(
def some_method
do_some_stuff
ensure
Expand All @@ -24,7 +24,6 @@ module Ameba::Rule::Lint
nil
end
)
subject.catch(s).should be_valid
end

it "fails if there is an empty ensure in method" do
Expand Down
6 changes: 2 additions & 4 deletions spec/ameba/rule/lint/empty_expression_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Ameba

describe Rule::Lint::EmptyExpression do
it "passes if there is no empty expression" do
s = Source.new %(
expect_no_issues subject, %(
def method()
end
Expand All @@ -31,7 +31,6 @@ module Ameba
begin "" end
[nil] << nil
)
subject.catch(s).should be_valid
end

it_detects_empty_expression %(())
Expand Down Expand Up @@ -96,7 +95,7 @@ module Ameba
)

it "does not report empty expression in macro" do
s = Source.new %q(
expect_no_issues subject, %q(
module MyModule
macro conditional_error_for_inline_callbacks
\{%
Expand All @@ -108,7 +107,6 @@ module Ameba
end
end
)
subject.catch(s).should be_valid
end

it "reports rule, location and message" do
Expand Down
9 changes: 3 additions & 6 deletions spec/ameba/rule/lint/empty_loop_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Ameba::Rule::Lint
subject = EmptyLoop.new

it "does not report if there are not empty loops" do
s = Source.new %(
expect_no_issues subject, %(
a = 1
while a < 10
Expand All @@ -20,7 +20,6 @@ module Ameba::Rule::Lint
a += 1
end
)
subject.catch(s).should be_valid
end

it "reports if there is an empty while loop" do
Expand All @@ -33,13 +32,12 @@ module Ameba::Rule::Lint
end

it "doesn't report if while loop has non-literals in cond block" do
s = Source.new %(
expect_no_issues subject, %(
a = 1
while a = gets.to_s
# nothing here
end
)
subject.catch(s).should be_valid
end

it "reports if there is an empty until loop" do
Expand All @@ -52,11 +50,10 @@ module Ameba::Rule::Lint
end

it "doesn't report if until loop has non-literals in cond block" do
s = Source.new %(
expect_no_issues subject, %(
until socket_open?
end
)
subject.catch(s).should be_valid
end

it "reports if there an empty loop" do
Expand Down
3 changes: 1 addition & 2 deletions spec/ameba/rule/lint/hash_duplicated_key_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ module Ameba::Rule::Lint
subject = HashDuplicatedKey.new

it "passes if there is no duplicated keys in a hash literals" do
s = Source.new %(
expect_no_issues subject, %(
h = {"a" => 1, :a => 2, "b" => 3}
h = {"a" => 1, "b" => 2, "c" => {"a" => 3, "b" => 4}}
h = {} of String => String
)
subject.catch(s).should be_valid
end

it "fails if there is a duplicated key in a hash literal" do
Expand Down
21 changes: 7 additions & 14 deletions spec/ameba/rule/lint/literal_in_condition_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Ameba::Rule::Lint

describe LiteralInCondition do
it "passes if there is not literals in conditional" do
s = Source.new %(
expect_no_issues subject, %(
if a == 2
:ok
end
Expand All @@ -23,7 +23,6 @@ module Ameba::Rule::Lint
:ok
end
)
subject.catch(s).should be_valid
end

it "fails if there is a predicate in if conditional" do
Expand Down Expand Up @@ -54,11 +53,10 @@ module Ameba::Rule::Lint
end

it "doesn't report range with non-literals" do
s = Source.new %(
expect_no_issues subject, %(
case (1..a)
end
)
subject.catch(s).should be_valid
end
end

Expand All @@ -76,7 +74,7 @@ module Ameba::Rule::Lint
end

it "doesn't report array with non-literals" do
s = Source.new %(
expect_no_issues subject, %(
a, b = 1, 2
case [1, 2, a]
when :array
Expand All @@ -85,7 +83,6 @@ module Ameba::Rule::Lint
:also_ok
end
)
subject.catch(s).should be_valid
end
end

Expand All @@ -101,23 +98,21 @@ module Ameba::Rule::Lint
end

it "doesn't report hash with non-literals in keys" do
s = Source.new %(
expect_no_issues subject, %(
case { a => 1, 33 => 'b' }
when :hash
:ok
end
)
subject.catch(s).should be_valid
end

it "doesn't report hash with non-literals in values" do
s = Source.new %(
expect_no_issues subject, %(
case { "name" => a, 33 => 'b' }
when :hash
:ok
end
)
subject.catch(s).should be_valid
end
end

Expand All @@ -133,14 +128,13 @@ module Ameba::Rule::Lint
end

it "doesn't report tuple with non-literals" do
s = Source.new %(
expect_no_issues subject, %(
a, b = 1, 2
case {1, b}
when {1, 2}
:ok
end
)
subject.catch(s).should be_valid
end
end

Expand All @@ -154,11 +148,10 @@ module Ameba::Rule::Lint
end

it "doesn't report named tuple with non-literals" do
s = Source.new %(
expect_no_issues subject, %(
case { name: a, foo: :bar}
end
)
subject.catch(s).should be_valid
end
end

Expand Down
3 changes: 1 addition & 2 deletions spec/ameba/rule/lint/literal_in_interpolation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ module Ameba::Rule::Lint

describe LiteralInInterpolation do
it "passes with good interpolation examples" do
s = Source.new %q(
expect_no_issues subject, %q(
name = "Ary"
"Hello, #{name}"
"#{name}"
"Name size: #{name.size}"
)
subject.catch(s).should be_valid
end

it "fails if there is useless interpolation" do
Expand Down
9 changes: 3 additions & 6 deletions spec/ameba/rule/lint/percent_arrays_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Ameba::Rule::Lint
subject = PercentArrays.new

it "passes if percent arrays are written correctly" do
s = Source.new %q(
expect_no_issues subject, %q(
%i(one two three)
%w(one two three)
Expand All @@ -15,7 +15,6 @@ module Ameba::Rule::Lint
%i()
%w()
)
subject.catch(s).should be_valid
end

it "fails if string percent array has commas" do
Expand Down Expand Up @@ -71,15 +70,13 @@ module Ameba::Rule::Lint
it "allows to configure string_array_unwanted_symbols" do
rule = PercentArrays.new
rule.string_array_unwanted_symbols = ","
s = Source.new %( %w("one") )
rule.catch(s).should be_valid
expect_no_issues rule, %( %w("one") )
end

it "allows to configure symbol_array_unwanted_symbols" do
rule = PercentArrays.new
rule.symbol_array_unwanted_symbols = ","
s = Source.new %( %i(:one) )
rule.catch(s).should be_valid
expect_no_issues rule, %( %i(:one) )
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/ameba/rule/lint/rand_zero_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ module Ameba::Rule::Lint
subject = RandZero.new

it "passes if it is not rand(1) or rand(0)" do
s = Source.new %(
expect_no_issues subject, %(
rand(1.0)
rand(0.11)
rand(2)
)
subject.catch(s).should be_valid
end

it "fails if it is rand(0)" do
Expand Down
15 changes: 5 additions & 10 deletions spec/ameba/rule/lint/redundant_string_cercion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ module Ameba::Rule::Lint
subject = RedundantStringCoercion.new

it "does not report if there is no redundant string coersion" do
s = Source.new %(
expect_no_issues subject, %(
"Hello, #{name}"
)
subject.catch(s).should be_valid
end

it "reports if there is a redundant string coersion" do
Expand All @@ -19,10 +18,9 @@ module Ameba::Rule::Lint
end

it "does not report if coersion is used in binary op" do
s = Source.new %q(
expect_no_issues subject, %q(
"Hello, #{3.to_s + 's'}"
)
subject.catch(s).should be_valid
end

it "reports if coercion is used with symbol literals" do
Expand Down Expand Up @@ -53,24 +51,21 @@ module Ameba::Rule::Lint
end

it "doesn't report if Object#to_s is called with arguments" do
s = Source.new %q(
expect_no_issues subject, %q(
/\w #{name.to_s(io)}/
)
subject.catch(s).should be_valid
end

it "doesn't report if Object#to_s is called without receiver" do
s = Source.new %q(
expect_no_issues subject, %q(
/\w #{to_s}/
)
subject.catch(s).should be_valid
end

it "doesn't report if Object#to_s is called with named args" do
s = Source.new %q(
expect_no_issues subject, %q(
"0x#{250.to_s base: 16}"
)
subject.catch(s).should be_valid
end

it "reports rule, location and message" do
Expand Down
Loading

0 comments on commit 4ec325c

Please sign in to comment.