Class: Ruptr::Compat::TestUnit

Inherits:
Ruptr::Compat show all
Defined in:
lib/ruptr/testunit.rb

Defined Under Namespace

Modules: DefBlockHelpers

Instance Method Summary collapse

Methods inherited from Ruptr::Compat

#adapted_test_suite, #each_default_project_test_file, #filter_test_group, #finalize_configuration!, #global_monkey_patch!, #global_uninstall!, #prepare_autorun!, #schedule_autorun!

Instance Method Details

#adapted_test_groupObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ruptr/testunit.rb', line 100

def adapted_test_group
  traverse = lambda do |klass|
    root = klass.equal?(adapter_module::TestCase)
    TestGroup.new(root ? "[TestUnit]" : klass.name,
                  identifier: root ? :testunit : klass.name).tap do |tg|
      klass.public_instance_methods(true)
           .filter { |sym| sym.start_with?('test_') }.each do |test_method_name|
        tc = TestCase.new(test_method_name.to_s, &make_run_block(klass, test_method_name))
        tg.add_test_case(tc)
      end
      klass.subclasses.each do |subklass|
        tg.add_test_subgroup(traverse.call(subklass))
      end
    end
  end
  traverse.call(adapter_module::TestCase)
end

#adapter_moduleObject



54
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
# File 'lib/ruptr/testunit.rb', line 54

def adapter_module
  @adapter_module ||= Module.new do
    extend(DefBlockHelpers)

    const_set :PendedError, Assertions::SkippedException
    const_set :AssertionFailedError, Assertions::AssertionError

    def_module(:Util) do
      extend(DefBlockHelpers)
      def_module(:Output) do
        def capture_output(&) = Assertions.capture_io(&)
      end
    end

    assertions_module = def_module(:Assertions) do
      include(Adapters::RuptrAssertions)
      # NOTE: Gem test-unit-ruby-core's "core_assertions" library will define some methods
      # directly in Test::Unit::Assertions.
    end

    def_class(:TestCase) do
      include(TestInstance)
      include(assertions_module)

      attr_accessor :method_name

      def setup = nil
      def teardown = nil
    end
  end
end

#default_project_load_pathsObject



11
# File 'lib/ruptr/testunit.rb', line 11

def default_project_load_paths = %w[test]

#default_project_test_globsObject



13
# File 'lib/ruptr/testunit.rb', line 13

def default_project_test_globs = %w[test/**/*[-_]test.rb test/**/test[-_]*.rb]

#global_install!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ruptr/testunit.rb', line 15

def global_install!
  m = if Object.const_defined?(:Test)
        Object.const_get(:Test)
      else
        Object.const_set(:Test, Module.new)
      end
  if m.const_defined?(:Unit)
    return if m.const_get(:Unit) == @adapter_module
    fail "test/unit already loaded!"
  end
  ::Test.const_set(:Unit, adapter_module)
  this = self
  m = Module.new do
    define_method(:require) do |name|
      name = name.to_path unless name.is_a?(String)
      case name
      when 'test/unit'
        return
      when 'test/unit/autorun'
        this.schedule_autorun!
        return
      when 'core_assertions'
        # Test::Unit::CoreAssertions#assert_separately spawns an interpreter with gems
        # disabled and include path arguments based on the current $LOAD_PATH.
        Gem.try_activate('test/unit')
      else
        fail "#{self.class.name}: unknown test/unit library: #{name}" if name.start_with?('test/unit/')
      end
      super(name)
    end
  end
  Kernel.prepend(m)
end