Type:
Module

Resolves a constant from a minitest spec name.

Given the following spec-style test:

1
2
3
4
5
6
7
8
9
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

The test will have the following name:

1
"WidgetsController::index::authenticated user::returns widgets"

The constant WidgetsController can be resolved from the name. The following code will resolve the constant:

1
2
3
controller = determine_constant_from_test_name(name) do |constant|
  Class === constant && constant < ::ActionController::Metal
end