Add line coverage for forked block via intercepting fork
This commit is contained in:
parent
0395838882
commit
511702af4c
2 changed files with 21 additions and 1 deletions
|
@ -40,7 +40,7 @@ module Mutant
|
|||
def self.call(&block)
|
||||
reader, writer = IO.pipe
|
||||
|
||||
pid = fork do
|
||||
pid = Process.fork do
|
||||
File.open('/dev/null', 'w') do |file|
|
||||
$stderr.reopen(file)
|
||||
reader.close
|
||||
|
|
|
@ -63,5 +63,25 @@ RSpec.describe Mutant::Isolation::Fork do
|
|||
$stderr = STDERR
|
||||
end
|
||||
end
|
||||
|
||||
# Spec stubbing out the fork to ensure all lines are covered
|
||||
# with expectations
|
||||
it 'covers all lines' do
|
||||
reader, writer = double('reader'), double('writer')
|
||||
expect(IO).to receive(:pipe).ordered.and_return([reader, writer])
|
||||
pid = double('PID')
|
||||
expect(Process).to receive(:fork).ordered.and_yield.and_return(pid)
|
||||
file = double('file')
|
||||
expect(File).to receive(:open).ordered.with('/dev/null', 'w').and_yield(file)
|
||||
expect($stderr).to receive(:reopen).ordered.with(file)
|
||||
expect(reader).to receive(:close).ordered
|
||||
expect(writer).to receive(:write).ordered.with(Marshal.dump(:foo))
|
||||
expect(writer).to receive(:close).ordered
|
||||
expect(writer).to receive(:close).ordered
|
||||
expect(reader).to receive(:read).ordered.and_return(Marshal.dump(:foo))
|
||||
expect(Process).to receive(:waitpid).with(pid)
|
||||
|
||||
expect(object.call { :foo }).to be(:foo)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue