Skip to content

Commit fe828c1

Browse files
authored
Merge pull request #606 from crystal-ameba/issue-605
Do not report `focus` values which aren't calls in `Lint/SpecFocus`
2 parents d172478 + 4405ccf commit fe828c1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

spec/ameba/rule/lint/spec_focus_spec.cr

+20
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ module Ameba::Rule::Lint
6060
subject.catch(s).should_not be_valid
6161
end
6262

63+
it "reports if there is a spec item with `focus: !true`" do
64+
s = Source.new %(
65+
it "it", focus: !true do
66+
end
67+
), path: "source_spec.cr"
68+
69+
subject.catch(s).should_not be_valid
70+
end
71+
6372
it "does not report if there is non spec block with :focus" do
6473
s = Source.new %(
6574
some_method "foo", focus: true do
@@ -69,6 +78,17 @@ module Ameba::Rule::Lint
6978
subject.catch(s).should be_valid
7079
end
7180

81+
it "does not report if is a parameterized focused spec item" do
82+
s = Source.new %(
83+
def assert_foo(focus = false)
84+
it "foo", focus: focus do
85+
end
86+
end
87+
), path: "source_spec.cr"
88+
89+
subject.catch(s).should be_valid
90+
end
91+
7292
it "does not report if there is a tagged item with :focus" do
7393
s = Source.new %(
7494
it "foo", tags: "focus" do

src/ameba/rule/lint/spec_focus.cr

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ module Ameba::Rule::Lint
6565
return unless node.block
6666

6767
arg = node.named_args.try &.find(&.name.== "focus")
68-
return unless arg
68+
return if arg.nil? ||
69+
arg.value.is_a?(Crystal::Call) ||
70+
arg.value.is_a?(Crystal::Var)
6971

7072
issue_for arg, MSG
7173
end

0 commit comments

Comments
 (0)