mirror of
https://github.com/Evolix/chexpire.git
synced 2024-06-30 04:52:52 +02:00
30 lines
810 B
Ruby
30 lines
810 B
Ruby
require "system_command"
|
|
|
|
module TestMocksHelper
|
|
# rubocop:disable Metrics/MethodLength
|
|
def mock_system_command(program, args, exit_status: 0, stdout: "", stderr: "")
|
|
syscmd = "#{program} #{Array.wrap(args).join(' ')}"
|
|
result = SystemCommandResult.new(syscmd, exit_status, stdout, stderr)
|
|
|
|
mock = Minitest::Mock.new
|
|
mock.expect :execute, result
|
|
|
|
assert_stub = lambda { |actual_program, actual_args, _logger|
|
|
assert_equal program, actual_program,
|
|
"SystemCommand was not initialized with the expected program name"
|
|
|
|
assert_equal args, actual_args,
|
|
"SystemCommand was not initialized with the expected arguments"
|
|
|
|
mock
|
|
}
|
|
|
|
SystemCommand.stub :new, assert_stub do
|
|
yield
|
|
end
|
|
|
|
mock.verify
|
|
end
|
|
# rubocop:enable Metrics/MethodLength
|
|
end
|