diff --git a/lib/minitest/thesis.rb b/lib/minitest/thesis.rb
index 44c190e..b767e53 100644
--- a/lib/minitest/thesis.rb
+++ b/lib/minitest/thesis.rb
@@ -327,16 +327,16 @@ module Minitest
# We enter the choices made in a tree.
node = @tree
- test_case.choices.each.with_index do |c, i|
- if i + 1 < test_case.choices.length || test_case.status == Status::OVERRUN
- if node.has_key?(c)
- node = node[c]
- else
- node = node[c] = {}
- end
- else
- node[c] = test_case.status
- end
+ *rest, last = test_case.choices
+ rest.each do |c|
+ node = if node.has_key?(c)
+ node[c]
+ else
+ node[c] = {}
+ end
+ end
+ unless last.nil?
+ node[last] = test_case.status == Status::OVERRUN ? {} : test_case.status
end
test_case.status
diff --git a/test/minitest/thesis_test.rb b/test/minitest/thesis_test.rb
index e6a453b..87cc8b8 100644
--- a/test/minitest/thesis_test.rb
+++ b/test/minitest/thesis_test.rb
@@ -471,6 +471,49 @@ class Minitest::ThesisTest < Minitest::Thesis
end
end
+ def test_refactoring_cache
+ old = ->(node, choices, status) {
+ choices.each.with_index do |c, i|
+ if i + 1 < choices.length || status == Status::OVERRUN
+ node = if node.has_key?(c)
+ node[c]
+ else
+ node[c] = {}
+ end
+ else
+ node[c] = status
+ end
+ end
+ }
+
+ new = ->(node, choices, status) {
+ *rest, last = choices
+ rest.each do |c|
+ node = if node.has_key?(c)
+ node[c]
+ else
+ node[c] = {}
+ end
+ end
+ unless last.nil?
+ node[last] = status == Status::OVERRUN ? {} : status
+ end
+ }
+
+ run_test("refactoring_cache", database: {}) do |tc|
+ old_tree = {}
+ new_tree = {}
+
+ choices = tc.any(lists(integers(0, 10)))
+ status = Status.new(tc.choice(4))
+
+ old.(old_tree, choices, status)
+ new.(new_tree, choices, status)
+
+ assert_equal old_tree, new_tree
+ end
+ end
+
private
def suppress_warnings