module RBS::UnitTest::TypeAssertions::ClassMethods - rbs: Ruby Standard Library Documentation

# module RBS::UnitTest::TypeAssertions::ClassMethods

### Attributes

target[R]

### Public Instance Methods

builder() click to toggle source

    # File rbs-3.8.0/lib/rbs/unit_test/type_assertions.rb, line 32
    def builder
      @builder ||= RBS::DefinitionBuilder.new(env: env)
    end

env() click to toggle source

    # File rbs-3.8.0/lib/rbs/unit_test/type_assertions.rb, line 20
    def env
      @env = @@env_cache[@libs] ||=
        begin
          loader = RBS::EnvironmentLoader.new
          (@libs || []).each do |lib|
            loader.add(library: lib, version: nil)
          end

          RBS::Environment.from_loader(loader).resolve_type_names
        end
    end

library(*libs) click to toggle source

    # File rbs-3.8.0/lib/rbs/unit_test/type_assertions.rb, line 8
    def library(*libs)
      if @libs
        raise "Multiple #library calls are not allowed"
      end

      @libs = libs
      @env = nil
      @target = nil
    end

testing(type_or_string) click to toggle source

    # File rbs-3.8.0/lib/rbs/unit_test/type_assertions.rb, line 36
    def testing(type_or_string)
      type = case type_or_string
             when String
               RBS::Parser.parse_type(type_or_string, variables: []) || raise
             else
               type_or_string
             end

      definition = case type
                   when RBS::Types::ClassInstance
                     builder.build_instance(type.name)
                   when RBS::Types::ClassSingleton
                     builder.build_singleton(type.name)
                   else
                     raise "Test target should be class instance or class singleton: #{type}"
                   end

      @target = [type, definition] #: [target_type, Definition]
    end