Sha256: 24f02d06b4551f954d6d839d66c0fc69144278708858e265596ef8b7c3637f70

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require "much-plugin"
require "scmd"

module GGem; end
module GGem::CmdTestsHelpers
  include MuchPlugin

  plugin_included do
    setup do
      ENV["SCMD_TEST_MODE"] = "1"

      @cmd_spy = nil
      Scmd.reset

      @exp_cmds_run = []
    end
    teardown do
      Scmd.reset
      ENV.delete("SCMD_TEST_MODE")
    end

    private

    def assert_exp_cmds_run(&run_cmd_block)
      cmd_str, exitstatus, stdout = run_cmd_block.call
      assert_equal @exp_cmds_run, Scmd.calls.map(&:cmd_str)

      assert_equal Scmd.calls.first.cmd_str,        cmd_str
      assert_equal Scmd.calls.first.cmd.exitstatus, exitstatus
      assert_equal Scmd.calls.first.cmd.stdout,     stdout
    end

    def assert_exp_cmds_error(cmd_error_class, &run_cmd_block)
      err_cmd_str = @exp_cmds_run.sample
      Scmd.add_command(err_cmd_str) do |cmd|
        cmd.exitstatus = 1
        cmd.stderr     = Factory.string
        @cmd_spy       = cmd
      end
      err = nil
      begin; run_cmd_block.call; rescue StandardError => err; end

      assert_kind_of cmd_error_class, err
      exp = "#{@cmd_spy.cmd_str}\n#{@cmd_spy.stderr}"
      assert_equal exp, err.message
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ggem-1.9.3 test/support/cmd_tests_helpers.rb
ggem-1.9.2 test/support/cmd_tests_helpers.rb