Class: Yamatanooroti::TestCase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/yamatanooroti.rb

Constant Summary collapse

@@runners =
[]

Class Method Summary collapse

Class Method Details

.inherited(klass) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/yamatanooroti.rb', line 55

def self.inherited(klass)
  super
  if ancestors.first == Yamatanooroti::TestCase
    if Yamatanooroti.has_vterm_gem?
      test_klass = Class.new(klass)
      klass.const_set(:TestVTerm, test_klass)
      test_klass.include Yamatanooroti::VTermTestCaseModule
      @@runners << test_klass
    end
    if Yamatanooroti.win?
      test_klass = Class.new(klass)
      klass.const_set(:TestWindows, test_klass)
      test_klass.include Yamatanooroti::WindowsTestCaseModule
      @@runners << test_klass
    end
    if @@runners.empty?
      raise LoadError.new(<<~EOM)
        Any real(?) terminal environments not found.
        Supporting real(?) terminals:
        - vterm gem
        - Windows
      EOM
    end
    def klass.method_added(name)
      super
      if ancestors[1] == Yamatanooroti::TestCase
        test_klass = @@runners.find { |test_klass| test_klass.ancestors.include?(self) }
        test_klass.define_method(name, instance_method(name))
        remove_method name
      end
    end
  end
end