Module: RBS::UnitTest::TypeAssertions::ClassMethods
- Defined in:
- lib/rbs/unit_test/type_assertions.rb
Constant Summary collapse
- @@env_cache =
{}
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/rbs/unit_test/type_assertions.rb', line 6 def target @target end |
Instance Method Details
#builder ⇒ Object
32 33 34 |
# File 'lib/rbs/unit_test/type_assertions.rb', line 32 def builder @builder ||= RBS::DefinitionBuilder.new(env: env) end |
#env ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |