Sha256: f8c0acf411cc0b282c3ebee792a3da22c8c072626173750c04dd78e0487da5b8

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

require "minitest/autorun"
require "pathname"
require "fileutils"

# Copied from https://github.com/splattael/minitest-around
# so as to avoid an explicit dependency
Minitest::Test.class_eval do
  alias_method :run_without_around, :run
  def run(*args)
    if defined?(around)
      result = nil
      around { result = run_without_around(*args) }
      result
    else
      run_without_around(*args)
    end
  end
end

module TestHelper
  def around(&block)
    Bundler.with_original_env do
      root = Pathname(__FILE__).dirname / ".." / ".."
      FileUtils.chdir root do
        block.()
      end
    end
  end

  def run_gli(args="", return_err_and_status: false, expect_failure: false)
    run_command("bin/gli",args,return_err_and_status:return_err_and_status,expect_failure:expect_failure)
  end

  def run_command(command,args,return_err_and_status:,expect_failure:,rubylib:nil)
    command_line_invocation = "#{command} #{args}"
    env = {}
    if !rubylib.nil?
      env["RUBYLIB"] = rubylib
    end
    stdout_string, stderr_string, status = Open3.capture3(env,command_line_invocation)
    if expect_failure
      refute_equal 0,status.exitstatus,"Expected failure for '#{command_line_invocation}' but it succeeded"
    else
      assert_equal 0,status.exitstatus,"Expected success for '#{command_line_invocation}' but it failed:\n#{stdout_string}\n\n#{stderr_string}\n\n"
    end
    if return_err_and_status
      [ stdout_string, stderr_string, status ]
    else
      stdout_string
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gli-2.22.0 test/integration/test_helper.rb
gli-2.21.5 test/integration/test_helper.rb
gli-2.21.4 test/integration/test_helper.rb
gli-2.21.3 test/integration/test_helper.rb
gli-2.21.2 test/integration/test_helper.rb
gli-2.21.1 test/integration/test_helper.rb
gli-2.21.0 test/integration/test_helper.rb
gli-2.20.1 test/integration/test_helper.rb
gli-2.20.0 test/integration/test_helper.rb