Class: RR::Integrations::MiniTest4

Inherits:
Object
  • Object
show all
Defined in:
lib/rr/integrations/minitest_4.rb

Direct Known Subclasses

Minitest

Defined Under Namespace

Modules: Mixin

Instance Method Summary collapse

Instance Method Details

#applies?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/rr/integrations/minitest_4.rb', line 14

def applies?
  mt_version < 5
rescue NameError
  false
end

#assertion_error_classObject



24
25
26
# File 'lib/rr/integrations/minitest_4.rb', line 24

def assertion_error_class
  ::MiniTest::Assertion
end

#hookObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rr/integrations/minitest_4.rb', line 36

def hook
  assertion_error_class = self.assertion_error_class
  test_case_class.class_eval do
    include RR::DSL
    include Mixin

    if defined?(::ActiveSupport::TestCase)
      is_active_support_test_case = lambda do |target|
        target.is_a?(::ActiveSupport::TestCase)
      end
    else
      is_active_support_test_case = lambda do |target|
        false
      end
    end

    unless instance_methods.any? { |method_name| method_name.to_sym == :setup_with_rr }
      alias_method :setup_without_rr, :setup
      define_method(:setup_with_rr) do
        setup_without_rr
        return if is_active_support_test_case.call(self)
        RR.reset
        RR.trim_backtrace = true
        RR.overridden_error_class = assertion_error_class
      end
      alias_method :setup, :setup_with_rr

      alias_method :teardown_without_rr, :teardown
      define_method(:teardown_with_rr) do
        begin
          RR.verify unless is_active_support_test_case.call(self)
        ensure
          teardown_without_rr
        end
      end
      alias_method :teardown, :teardown_with_rr
    end
  end
end

#mt_versionObject



32
33
34
# File 'lib/rr/integrations/minitest_4.rb', line 32

def mt_version
  version_constant.split('.')[0].to_i
end

#nameObject



10
11
12
# File 'lib/rr/integrations/minitest_4.rb', line 10

def name
  'MiniTest 4'
end

#test_case_classObject



20
21
22
# File 'lib/rr/integrations/minitest_4.rb', line 20

def test_case_class
  ::MiniTest::Unit::TestCase
end

#version_constantObject



28
29
30
# File 'lib/rr/integrations/minitest_4.rb', line 28

def version_constant
  ::MiniTest::Unit::VERSION
end