mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Enhance spec helpers a bit in re: to the spec context
This commit is contained in:
parent
e9f3bbaeff
commit
1ba6fcb55c
8 changed files with 47 additions and 47 deletions
|
@ -3,11 +3,11 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Lint::EmptyExpression.new
|
||||
|
||||
private def it_detects_empty_expression(code)
|
||||
it %(detects empty expression "#{code}") do
|
||||
private def it_detects_empty_expression(code, *, file = __FILE__, line = __LINE__)
|
||||
it %(detects empty expression "#{code}"), file, line do
|
||||
s = Source.new code
|
||||
rule = Rule::Lint::EmptyExpression.new
|
||||
rule.catch(s).should_not be_valid
|
||||
rule.catch(s).should_not be_valid, file: file, line: line
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Style::ConstantNames.new
|
||||
|
||||
private def it_reports_constant(name, value, expected)
|
||||
it "reports constant name #{expected}" do
|
||||
private def it_reports_constant(name, value, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports constant name #{expected}", file, line do
|
||||
rule = Rule::Style::ConstantNames.new
|
||||
expect_issue rule, <<-CRYSTAL, name: name
|
||||
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||
%{name} = #{value}
|
||||
# ^{name} error: Constant name should be screaming-cased: #{expected}, not #{name}
|
||||
CRYSTAL
|
||||
|
|
|
@ -3,11 +3,11 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Style::GuardClause.new
|
||||
|
||||
private def it_reports_body(body, *, line = __LINE__)
|
||||
private def it_reports_body(body, *, file = __FILE__, line = __LINE__)
|
||||
rule = Rule::Style::GuardClause.new
|
||||
|
||||
it "reports an issue if method body is if / unless without else" do
|
||||
source = expect_issue rule, <<-CRYSTAL, line: line
|
||||
it "reports an issue if method body is if / unless without else", file, line do
|
||||
source = expect_issue rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
# ^^ error: Use a guard clause (`return unless something`) instead of wrapping the code inside a conditional expression.
|
||||
|
@ -23,7 +23,7 @@ module Ameba
|
|||
end
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL, line: line
|
||||
expect_correction source, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
return unless something
|
||||
#{body}
|
||||
|
@ -38,8 +38,8 @@ module Ameba
|
|||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports an issue if method body ends with if / unless without else" do
|
||||
source = expect_issue rule, <<-CRYSTAL, line: line
|
||||
it "reports an issue if method body ends with if / unless without else", file, line do
|
||||
source = expect_issue rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
test
|
||||
if something
|
||||
|
@ -57,7 +57,7 @@ module Ameba
|
|||
end
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL, line: line
|
||||
expect_correction source, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
test
|
||||
return unless something
|
||||
|
@ -75,11 +75,11 @@ module Ameba
|
|||
end
|
||||
end
|
||||
|
||||
private def it_reports_control_expression(kw, *, line = __LINE__)
|
||||
private def it_reports_control_expression(kw, *, file = __FILE__, line = __LINE__)
|
||||
rule = Rule::Style::GuardClause.new
|
||||
|
||||
it "reports an issue with #{kw} in the if branch" do
|
||||
source = expect_issue rule, <<-CRYSTAL, line: line
|
||||
it "reports an issue with #{kw} in the if branch", file, line do
|
||||
source = expect_issue rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
# ^^ error: Use a guard clause (`#{kw} if something`) instead of wrapping the code inside a conditional expression.
|
||||
|
@ -90,11 +90,11 @@ module Ameba
|
|||
end
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source, line: line
|
||||
expect_no_corrections source, file: file, line: line
|
||||
end
|
||||
|
||||
it "reports an issue with #{kw} in the else branch" do
|
||||
source = expect_issue rule, <<-CRYSTAL, line: line
|
||||
it "reports an issue with #{kw} in the else branch", file, line do
|
||||
source = expect_issue rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
# ^^ error: Use a guard clause (`#{kw} unless something`) instead of wrapping the code inside a conditional expression.
|
||||
|
@ -105,11 +105,11 @@ module Ameba
|
|||
end
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source, line: line
|
||||
expect_no_corrections source, file: file, line: line
|
||||
end
|
||||
|
||||
it "doesn't report an issue if condition has multiple lines" do
|
||||
expect_no_issues rule, <<-CRYSTAL, line: line
|
||||
it "doesn't report an issue if condition has multiple lines", file, line do
|
||||
expect_no_issues rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something &&
|
||||
something_else
|
||||
|
@ -121,8 +121,8 @@ module Ameba
|
|||
CRYSTAL
|
||||
end
|
||||
|
||||
it "does not report an issue if #{kw} is inside elsif" do
|
||||
expect_no_issues rule, <<-CRYSTAL, line: line
|
||||
it "does not report an issue if #{kw} is inside elsif", file, line do
|
||||
expect_no_issues rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
a
|
||||
|
@ -133,8 +133,8 @@ module Ameba
|
|||
CRYSTAL
|
||||
end
|
||||
|
||||
it "does not report an issue if #{kw} is inside if..elsif..else..end" do
|
||||
expect_no_issues rule, <<-CRYSTAL, line: line
|
||||
it "does not report an issue if #{kw} is inside if..elsif..else..end", file, line do
|
||||
expect_no_issues rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
a
|
||||
|
@ -147,8 +147,8 @@ module Ameba
|
|||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report an issue if control flow expr has multiple lines" do
|
||||
expect_no_issues rule, <<-CRYSTAL, line: line
|
||||
it "doesn't report an issue if control flow expr has multiple lines", file, line do
|
||||
expect_no_issues rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
#{kw} \\
|
||||
|
@ -161,8 +161,8 @@ module Ameba
|
|||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports an issue if non-control-flow branch has multiple lines" do
|
||||
source = expect_issue rule, <<-CRYSTAL, line: line
|
||||
it "reports an issue if non-control-flow branch has multiple lines", file, line do
|
||||
source = expect_issue rule, <<-CRYSTAL, file: file, line: line
|
||||
def func
|
||||
if something
|
||||
# ^^ error: Use a guard clause (`#{kw} if something`) instead of wrapping the code inside a conditional expression.
|
||||
|
@ -174,7 +174,7 @@ module Ameba
|
|||
end
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source, line: line
|
||||
expect_no_corrections source, file: file, line: line
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Style::LargeNumbers.new
|
||||
|
||||
private def it_transforms(number, expected)
|
||||
it "transforms large number #{number}" do
|
||||
private def it_transforms(number, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "transforms large number #{number}", file, line do
|
||||
rule = Rule::Style::LargeNumbers.new
|
||||
rule.int_min_digits = 5
|
||||
|
||||
source = expect_issue rule, <<-CRYSTAL, number: number
|
||||
source = expect_issue rule, <<-CRYSTAL, number: number, file: file, line: line
|
||||
number = %{number}
|
||||
# ^{number} error: Large numbers should be written with underscores: #{expected}
|
||||
CRYSTAL
|
||||
|
|
|
@ -3,10 +3,10 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Style::MethodNames.new
|
||||
|
||||
private def it_reports_method_name(name, expected)
|
||||
it "reports method name #{expected}" do
|
||||
private def it_reports_method_name(name, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports method name #{expected}", file, line do
|
||||
rule = Rule::Style::MethodNames.new
|
||||
expect_issue rule, <<-CRYSTAL, name: name
|
||||
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||
def %{name}; end
|
||||
# ^{name} error: Method name should be underscore-cased: #{expected}, not %{name}
|
||||
CRYSTAL
|
||||
|
|
|
@ -3,10 +3,10 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Style::TypeNames.new
|
||||
|
||||
private def it_reports_name(type, name, expected)
|
||||
it "reports type name #{expected}" do
|
||||
private def it_reports_name(type, name, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports type name #{expected}", file, line do
|
||||
rule = Rule::Style::TypeNames.new
|
||||
expect_issue rule, <<-CRYSTAL, type: type, name: name
|
||||
expect_issue rule, <<-CRYSTAL, type: type, name: name, file: file, line: line
|
||||
%{type} %{name}; end
|
||||
# ^{type}^{name}^^^^ error: Type name should be camelcased: #{expected}, but it was %{name}
|
||||
CRYSTAL
|
||||
|
|
|
@ -3,10 +3,10 @@ require "../../../spec_helper"
|
|||
module Ameba
|
||||
subject = Rule::Style::VariableNames.new
|
||||
|
||||
private def it_reports_var_name(name, value, expected)
|
||||
it "reports variable name #{expected}" do
|
||||
private def it_reports_var_name(name, value, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "reports variable name #{expected}", file, line do
|
||||
rule = Rule::Style::VariableNames.new
|
||||
expect_issue rule, <<-CRYSTAL, name: name
|
||||
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
|
||||
%{name} = #{value}
|
||||
# ^{name} error: Var name should be underscore-cased: #{expected}, not %{name}
|
||||
CRYSTAL
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require "../spec_helper"
|
||||
|
||||
module Ameba
|
||||
private def it_tokenizes(str, expected)
|
||||
it "tokenizes #{str}" do
|
||||
([] of String).tap do |token_types|
|
||||
private def it_tokenizes(str, expected, *, file = __FILE__, line = __LINE__)
|
||||
it "tokenizes #{str}", file, line do
|
||||
%w[].tap do |token_types|
|
||||
Tokenizer.new(Source.new str, normalize: false)
|
||||
.run { |token| token_types << token.type.to_s }
|
||||
.should be_true
|
||||
end.should eq expected
|
||||
end.should eq(expected), file: file, line: line
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue