Module: RBS::Test::TypeAssertions::ClassMethods

Defined in:
lib/rbs/test/test_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/rbs/test/test_helper.rb', line 5

def target
  @target
end

Instance Method Details

#builderObject



26
27
28
# File 'lib/rbs/test/test_helper.rb', line 26

def builder
  @builder ||= DefinitionBuilder.new(env: env)
end

#envObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rbs/test/test_helper.rb', line 13

def env
  @env ||= begin
             loader = RBS::EnvironmentLoader.new
             (@libs || []).each do |lib|
               loader.add library: lib
             end

             RBS::Environment.new.tap do |env|
               loader.load(env: env)
             end
           end
end

#library(*libs) ⇒ Object



7
8
9
10
11
# File 'lib/rbs/test/test_helper.rb', line 7

def library(*libs)
  @libs = libs
  @env = nil
  @target = nil
end

#testing(type_or_string) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rbs/test/test_helper.rb', line 30

def testing(type_or_string)
  type = case type_or_string
         when String
           RBS::Parser.parse_type(type_or_string, variables: [])
         else
           type_or_string
         end

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

  @target = [type, definition]
end