Skip to content

Commit 82b9b6d

Browse files
committed
Refer to mentor when code does not match criteria
1 parent e79d8e1 commit 82b9b6d

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

lib/analyzers/acronym/analyze.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def analyze!
1010
approve! if approve_without_comment?
1111

1212
approve!(:use_shorthand_block_syntax) if solution.uses_method_chain_with_block?
13+
14+
refer_to_mentor!
1315
end
1416

1517
private
@@ -24,5 +26,11 @@ def approve!(msg = nil)
2426

2527
raise FinishedFlowControlException
2628
end
29+
30+
def refer_to_mentor!
31+
self.status = :refer_to_mentor
32+
33+
raise FinishedFlowControlException
34+
end
2735
end
2836
end

lib/analyzers/acronym/representation.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def uses_method_chain_with_block?
4242
type: :block,
4343
method_name: :map,
4444
chained?: true,
45-
arguments: s(:args, s(:arg, :word)),
46-
body: s(:send, s(:lvar, :word), :chr)
45+
arguments: s(:args, s(:arg, :word))
4746
},
4847
{
4948
method_name: :map,
@@ -57,6 +56,10 @@ def uses_method_chain_with_block?
5756
receiver: s(:lvar, :words),
5857
chained?: true,
5958
arguments: [{ to_ast: s(:str, "-") }, { to_ast: s(:str, " ") }]
59+
},
60+
{
61+
method_name: :chr,
62+
receiver: s(:lvar, :word)
6063
}
6164
]
6265

@@ -127,7 +130,7 @@ def matches?(body, matchers, types = [:send])
127130

128131
def node_matches?(node, matcher)
129132
matcher.
130-
map do |criteria|
133+
all? do |criteria|
131134
key, expected_value = *criteria
132135
criteria_value = node.send(key)
133136

@@ -139,8 +142,7 @@ def node_matches?(node, matcher)
139142
else
140143
criteria_value == expected_value
141144
end
142-
end.
143-
all?
145+
end
144146
end
145147
end
146148
end

test/exercises/acronym_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,30 @@ def self.abbreviate(words)
4141
assert_equal [], results[:comments]
4242
end
4343

44+
def test_refers_to_mentor_with_method_not_matching
45+
source = %q{
46+
class Acronym
47+
def self.abbreviate(words)
48+
test.words.tr('-', ' ').split.map(&:chr).join.upcase
49+
end
50+
end
51+
}
52+
results = Acronym::Analyze.(source)
53+
assert_equal :refer_to_mentor, results[:status]
54+
end
55+
56+
def test_refers_to_mentor_with_random_method_body
57+
source = %q{
58+
class Acronym
59+
def self.abbreviate(words)
60+
anything_here.123.456.test_method
61+
end
62+
end
63+
}
64+
results = Acronym::Analyze.(source)
65+
assert_equal :refer_to_mentor, results[:status]
66+
end
67+
4468
def test_scan_with_any_regex_passes
4569
source = %q{
4670
class Acronym

0 commit comments

Comments
 (0)