Module: RBS::UnitTest::TypeAssertions::ClassMethods
Relationships & Source Files | |
Defined in: | lib/rbs/unit_test/type_assertions.rb |
Instance Attribute Summary
- #target readonly
Instance Method Summary
Instance Attribute Details
#target (readonly)
[ GitHub ]# File 'lib/rbs/unit_test/type_assertions.rb', line 6
attr_reader :target
Instance Method Details
#builder
[ GitHub ]# File 'lib/rbs/unit_test/type_assertions.rb', line 32
def builder @builder ||= RBS::DefinitionBuilder.new(env: env) end
#env
[ GitHub ]# File '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)
[ GitHub ]# File '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)
[ GitHub ]# File '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