Sha256: 2d83be29ed09a8bff699adbfa699110c74933e55bfcf715251228a4fc1b09782

Contents?: true

Size: 1.42 KB

Versions: 107

Compression:

Stored size: 1.42 KB

Contents

require "active_support/concern"
require "active_support/inflector"

module ActiveSupport
  module Testing
    # Resolves a constant from a minitest spec name.
    #
    # Given the following spec-style test:
    #
    #   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:
    #
    #   "WidgetsController::index::authenticated user::returns widgets"
    #
    # The constant WidgetsController can be resolved from the name.
    # The following code will resolve the constant:
    #
    #   controller = determine_constant_from_test_name(name) do |constant|
    #     Class === constant && constant < ::ActionController::Metal
    #   end
    module ConstantLookup
      extend ::ActiveSupport::Concern

      module ClassMethods  # :nodoc:
        def determine_constant_from_test_name(test_name)
          names = test_name.split "::"
          while names.size > 0 do
            names.last.sub!(/Test$/, "")
            begin
              constant = names.join("::").safe_constantize
              break(constant) if yield(constant)
            ensure
              names.pop
            end
          end
        end
      end

    end
  end
end

Version data entries

107 entries across 102 versions & 15 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/testing/constant_lookup.rb
activesupport-4.2.11.3 lib/active_support/testing/constant_lookup.rb
activesupport-4.2.11.2 lib/active_support/testing/constant_lookup.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/testing/constant_lookup.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/testing/constant_lookup.rb
activesupport-5.0.7.2 lib/active_support/testing/constant_lookup.rb
activesupport-4.2.11.1 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.7.1 lib/active_support/testing/constant_lookup.rb
activesupport-4.2.11 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.7 lib/active_support/testing/constant_lookup.rb
activesupport-4.2.10 lib/active_support/testing/constant_lookup.rb
activesupport-4.2.10.rc1 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.6 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.6.rc1 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.5 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.5.rc2 lib/active_support/testing/constant_lookup.rb
activesupport-5.0.5.rc1 lib/active_support/testing/constant_lookup.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/constant_lookup.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/testing/constant_lookup.rb
activesupport-4.2.9 lib/active_support/testing/constant_lookup.rb