从 minitest 测试名称解析常量。
假设以下规范风格测试
describe WidgetsController, :index do
describe "authenticated user" do
describe "returns widgets" do
it "has a controller that exists" do
assert_kind_of WidgetsController, @controller
end
end
end
end
测试将具有以下名称
"WidgetsController::index::authenticated user::returns widgets"
常量 WidgetsController 可以从名称解析。以下代码将解析常量
controller = determine_constant_from_test_name(name) do |constant|
Class === constant && constant < ::ActionController::Metal
end