Module: RBS::Test::TypeAssertions

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



51
52
53
# File 'lib/rbs/test/test_helper.rb', line 51

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#builderObject



59
60
61
# File 'lib/rbs/test/test_helper.rb', line 59

def builder
  self.class.builder
end

#envObject



55
56
57
# File 'lib/rbs/test/test_helper.rb', line 55

def env
  self.class.env
end

#targetObject



67
68
69
# File 'lib/rbs/test/test_helper.rb', line 67

def target
  targets.last || self.class.target
end

#targetsObject



63
64
65
# File 'lib/rbs/test/test_helper.rb', line 63

def targets
  @targets ||= []
end

#testing(type_or_string) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rbs/test/test_helper.rb', line 71

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

  targets.push [type, definition]

  if block_given?
    begin
      yield
    ensure
      targets.pop
    end
  else
    [type, definition]
  end
end