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
require_relative "../test_helper"

# ProTacts.silence_warnings, the block helper behind the quiet phlex
# requires: warnings off inside, back on after — including when the
# block raises, which is the half a missing ensure would get wrong
# only when something has already failed.
class ProTactsWarningsTest < Minitest::Test
  def test_silences_warnings_for_the_block_and_restores_them_after
    verbose = $VERBOSE
    ProTacts.silence_warnings do
      assert_nil $VERBOSE
    end
    assert_equal verbose, $VERBOSE
  end

  def test_restores_warnings_when_the_block_raises
    verbose = $VERBOSE

    assert_raises(RuntimeError) do
      ProTacts.silence_warnings do
        raise "boom"
      end
    end

    assert_equal verbose, $VERBOSE
  end
end