Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
- $CHILD_STATUS could not be mocked, so extracted to class
  • Loading branch information
kobaltz committed Mar 3, 2024
1 parent cb84e97 commit d6a50a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/clamby/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def self.scan_executable
return 'clamscan'
end

# $CHILD_STATUS maybe nil if the execution itself (not the client process)
def self.scan_status
$CHILD_STATUS && $CHILD_STATUS.exitstatus
end

# Perform a ClamAV scan on the given path.
def self.scan(path)
return nil unless file_exists?(path)
Expand All @@ -28,10 +33,7 @@ def self.scan(path)

new.run scan_executable, *args

# $CHILD_STATUS maybe nil if the execution itself (not the client process)
# fails
child_status = $CHILD_STATUS.dup # $CHILD_STATUS in Ruby 3.0+ is frozen
case child_status && child_status.exitstatus
case self.scan_status
when 0
return false
when nil, 2
Expand Down
2 changes: 1 addition & 1 deletion lib/clamby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Clamby
VERSION = "1.6.10"
VERSION = "1.6.11"
end
10 changes: 8 additions & 2 deletions spec/clamby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@
}

context 'when false' do
before { Clamby.configure(error_clamscan_client_error: false) }
before do
Clamby.configure(error_clamscan_client_error: false)
allow(Clamby::Command).to receive(:scan_status).and_return(2)
end

it 'virus? returns true when the daemonized client exits with status 2' do
Clamby.configure(daemonize: true)
Expand All @@ -107,7 +110,10 @@
end

context 'when true' do
before { Clamby.configure(error_clamscan_client_error: true) }
before do
Clamby.configure(error_clamscan_client_error: true)
allow(Clamby::Command).to receive(:scan_status).and_return(2)
end

it 'virus? raises when the daemonized client exits with status 2' do
Clamby.configure(daemonize: true)
Expand Down

0 comments on commit d6a50a6

Please sign in to comment.