File: example.rb

package info (click to toggle)
ruby-minitest-hooks 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 156 kB
  • sloc: ruby: 600; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 1,844 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require './spec/helper'
require 'minitest/hooks/default'

error = ENV['MINITEST_HOOKS_ERRORS']

module Minitest
  def self.plugin_result_inspector_reporter_init(options)
    self.reporter << ResultInspectorReporter.new(options[:io], options)
  end

  class ResultInspectorReporter < SummaryReporter
    def report
      results.each do |result|
        io.puts "result to_s: #{result.to_s.inspect}"
        # For Minitest 5.11+, we expect Minitest::Result objects.
        if defined?(Minitest::Result)
          io.puts "result source_location: #{result.source_location.inspect}"
        else
          # For older versions of Minitest, extract source_location in a
          # similar fashion to how some third party reporters expected to be
          # able to:
          # https://github.com/circleci/minitest-ci/blob/8b72b0f32f154d91b53d63d1d0a8a8fb3b01d726/lib/minitest/ci_plugin.rb#L139
          io.puts "result source_location: #{result.method(result.name).source_location.inspect}"
        end
      end
    end
  end
end

Minitest.extensions << "result_inspector_reporter"

describe 'Minitest::Hooks error handling' do
  before(:all) do
    raise if error == 'before-all'
  end
  before do
    raise if error == 'before'
  end
  after do
    raise if error == 'after'
  end
  after(:all) do
    raise if error == 'after-all'
  end
  around do |&block|
    raise if error == 'around-before'
    super(&block)
    raise if error == 'around-after'
  end
  around(:all) do |&block|
    raise if error == 'around-all-before'
    super(&block)
    case error
    when 'before-all'
      name.must_equal 'before_all'
    when 'after-all'
      name.must_equal 'after_all'
    else
      name.must_equal 'around_all'
    end
    raise if error == 'around-all-after'
  end

  3.times do |i|
    it "should work try #{i}" do
    end
  end
end