From a2fddbdcf47958b32b17468a5e03730d324b124e Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Sat, 2 Oct 2021 09:10:09 +0900 Subject: [PATCH] Fix: TypeError: can't convert ImageOptim::Timer into Float --- lib/image_optim/cmd.rb | 2 +- spec/image_optim/cmd_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/image_optim/cmd.rb b/lib/image_optim/cmd.rb index ea00a282..4957f8d4 100644 --- a/lib/image_optim/cmd.rb +++ b/lib/image_optim/cmd.rb @@ -17,7 +17,7 @@ def run(*args) pid = Process.spawn(*args) waiter = Process.detach(pid) - if waiter.join(timeout) + if waiter.join(timeout.to_f) status = waiter.value check_status!(status) diff --git a/spec/image_optim/cmd_spec.rb b/spec/image_optim/cmd_spec.rb index 090784cd..44a94d1e 100644 --- a/spec/image_optim/cmd_spec.rb +++ b/spec/image_optim/cmd_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' require 'image_optim/cmd' +require 'image_optim/timer' describe ImageOptim::Cmd do before do @@ -48,6 +49,11 @@ def expect_int_exception(&block) expect(Cmd.run('sh -c "exit 66"', timeout: 1)).to eq(false) end + it 'returns process success status when timeout is instance of ImageOptim::Timer' do + timeout = ImageOptim::Timer.new(1.0) + expect(Cmd.run('sh -c "exit 0"', timeout: timeout)).to eq(true) + end + it 'raises SignalException if process terminates after signal', skip: SkipConditions[:signals_support] do expect_int_exception do Cmd.run('kill -s INT $$', timeout: 1)