|
20 | 20 | require 'fileutils'
|
21 | 21 | FileUtils.mkdir_p(File.expand_path('../../tmp/cache', __FILE__))
|
22 | 22 |
|
23 |
| -# https://github.com/seattlerb/minitest/blob/master/lib/minitest/autorun.rb |
24 | 23 | gem 'minitest'
|
25 | 24 | begin
|
26 | 25 | require 'minitest'
|
27 | 26 | rescue LoadError
|
28 | 27 | # Minitest 4
|
29 |
| - require 'minitest/unit' |
30 |
| - require 'minitest/spec' |
31 |
| - require 'minitest/mock' |
| 28 | + require 'minitest/autorun' |
32 | 29 | $minitest_version = 4
|
33 |
| - # Minitest 4 |
34 | 30 | # https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/autorun.rb
|
35 | 31 | # https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787
|
36 | 32 | # Ensure backward compatibility with Minitest 4
|
37 | 33 | Minitest = MiniTest unless defined?(Minitest)
|
38 | 34 | Minitest::Test = MiniTest::Unit::TestCase
|
39 |
| - minitest_run = ->(argv) { MiniTest::Unit.new.run(argv) } |
40 | 35 | else
|
41 | 36 | # Minitest 5
|
| 37 | + require 'minitest/autorun' |
42 | 38 | $minitest_version = 5
|
43 |
| - # Minitest 5 |
44 | 39 | # https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
|
45 | 40 | # https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
|
46 |
| - require 'minitest/spec' |
47 |
| - require 'minitest/mock' |
48 |
| - minitest_run = ->(argv) { Minitest.run(argv) } |
49 | 41 | end
|
50 | 42 | require 'minitest/reporters'
|
51 | 43 | Minitest::Reporters.use!
|
52 | 44 |
|
53 |
| -# If there's no failure info, try disabling capturing stderr: |
54 |
| -# `env CAPTURE_STDERR=false rake` |
55 |
| -# This is way easier than writing a Minitest plugin |
56 |
| -# for 4.x and 5.x. |
57 |
| -if ENV['CAPTURE_STDERR'] !~ /false|1/i |
58 |
| - require 'capture_warnings' |
59 |
| - minitest_run = CaptureWarnings.new(_fail_build = true).execute!(minitest_run) |
60 |
| -else |
61 |
| - $VERBOSE = true |
62 |
| -end |
63 |
| - |
64 | 45 | require 'active_model_serializers'
|
65 | 46 | require 'active_model/serializer/railtie'
|
66 | 47 |
|
|
82 | 63 | $action_controller_logger = ActiveModelSerializers.logger
|
83 | 64 | ActiveModelSerializers.logger = Logger.new(IO::NULL)
|
84 | 65 | end
|
85 |
| - |
86 |
| -# From: |
87 |
| -# https://github.com/seattlerb/minitest/blob/644a52fd0/lib/minitest/unit.rb#L768-L787 |
88 |
| -# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59 |
89 |
| -# But we've replaced `at_exit` with `END` called before the 'at_exit' hook. |
90 |
| -class MiniTestHack |
91 |
| - def self.autorun(minitest_run) |
92 |
| - # don't run if there was a non-exit exception |
93 |
| - return if $! and not ($!.kind_of? SystemExit and $!.success?) |
94 |
| - |
95 |
| - # Original Comment: |
96 |
| - # the order here is important. The at_exit handler must be |
97 |
| - # installed before anyone else gets a chance to install their |
98 |
| - # own, that way we can be assured that our exit will be last |
99 |
| - # to run (at_exit stacks). |
100 |
| - # |
101 |
| - # Now: |
102 |
| - # The after_run blocks now only run on SigEXIT, which is fine. |
103 |
| - exit_code = nil |
104 |
| - |
105 |
| - trap('EXIT') do |
106 |
| - if $minitest_version == 5 |
107 |
| - @@after_run.reverse_each(&:call) |
108 |
| - else |
109 |
| - @@after_tests.reverse_each(&:call) |
110 |
| - end |
111 |
| - |
112 |
| - exit exit_code || false |
113 |
| - end |
114 |
| - |
115 |
| - exit_code = minitest_run.call(ARGV) |
116 |
| - end |
117 |
| -end |
118 |
| -# Run MiniTest in `END`, so that it finishes before `at_exit` fires, |
119 |
| -# which guarantees we can run code after MiniTest finishes |
120 |
| -# via an `at_exit` block. |
121 |
| -# This is in service of silencing non-app warnings during test run, |
122 |
| -# and leaves us with the warnings in our app. |
123 |
| -END { MiniTestHack.autorun(minitest_run) } |
0 commit comments