Sha256: 3baec69072b0dcb1beb6775257441f43b822424d7288e91a93546b5695653816

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

module Minitest::Assertions
  def assert_parses_correctly(parser, commandline, expected_opts,
                              expected_leftovers)
    opts = parser.parse commandline
    assert_equal expected_opts, opts
    assert_equal expected_leftovers, parser.leftovers
  end

  def assert_stderr(str = nil, msg = nil)
    msg = "#{msg}.\n" if msg

    old_stderr, $stderr = $stderr, StringIO.new('')
    yield
    assert_match str, $stderr.string, msg if str
  ensure
    $stderr = old_stderr
  end

  def assert_stdout(str = nil, msg = nil)
    msg = "#{msg}.\n" if msg

    old_stdout, $stdout = $stdout, StringIO.new('')
    yield
    assert_match str, $stdout.string, msg if str
  ensure
    $stdout = old_stdout
  end

  # like assert raises, but if it does raise, it checks status
  # NOTE: this does not ensure the exception is raised
  def assert_system_exit *exp
    msg = "#{exp.pop}.\n" if String === exp.last
    status = exp.first

    begin
      yield
    rescue SystemExit => e
      assert_equal status, e.status {
        exception_details(e, "#{msg}#{mu_pp(exp)} exception expected, not")
      } if status
      return true
    end
    flunk "#{msg}#{mu_pp(exp)} SystemExit expected but nothing was raised."
  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
optimist-3.1.0 test/support/assert_helpers.rb
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.1/test/support/assert_helpers.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.1/test/support/assert_helpers.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.1/test/support/assert_helpers.rb
optimist-3.0.1 test/support/assert_helpers.rb
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.0/test/support/assert_helpers.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.0/test/support/assert_helpers.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.0/test/support/assert_helpers.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.0/test/support/assert_helpers.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/optimist-3.0.0/test/support/assert_helpers.rb
trollop-2.9.10 test/support/assert_helpers.rb
trollop-2.9.9 test/support/assert_helpers.rb
optimist-3.0.0 test/support/assert_helpers.rb
trollop-2.1.3 test/support/assert_helpers.rb