2014-06-08 13:55:13 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Mutant::Isolation do
|
|
|
|
describe '.isolate' do
|
|
|
|
let(:object) { described_class }
|
|
|
|
|
2014-06-09 11:36:00 -04:00
|
|
|
before do
|
2014-06-14 10:28:54 -04:00
|
|
|
unless RUBY_VERSION.eql?('2.1.2')
|
|
|
|
skip 'Series of events is indeterministic cross ruby implementations. Skipping this test under non 2.1.2'
|
|
|
|
end
|
2014-06-09 11:36:00 -04:00
|
|
|
end
|
|
|
|
|
2014-06-08 13:55:13 -04:00
|
|
|
let(:expected_return) { :foo }
|
|
|
|
|
|
|
|
subject { object.call(&block) }
|
|
|
|
|
|
|
|
def redirect_stderr
|
|
|
|
$stderr = File.open('/dev/null')
|
|
|
|
end
|
|
|
|
|
|
|
|
unless ENV['COVERAGE']
|
|
|
|
context 'when block returns mashallable data, and process exists zero' do
|
|
|
|
let(:block) do
|
|
|
|
lambda do
|
|
|
|
:data_from_child_process
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it { should eql(:data_from_child_process) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when block does return marshallable data' do
|
|
|
|
let(:block) do
|
|
|
|
lambda do
|
|
|
|
redirect_stderr
|
2014-06-08 15:51:04 -04:00
|
|
|
$stderr # not mashallable, nothing written to pipe and raises exception in child
|
2014-06-08 13:55:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an exception' do
|
|
|
|
expect { subject }.to raise_error(described_class::Error, 'Childprocess wrote un-unmarshallable data')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-08 15:51:04 -04:00
|
|
|
context 'when block causes the child to exit nonzero' do
|
2014-06-08 13:55:13 -04:00
|
|
|
let(:block) do
|
|
|
|
lambda do
|
2014-06-08 15:51:04 -04:00
|
|
|
method = Kernel.method(:exit!)
|
|
|
|
Kernel.define_singleton_method(:exit!) do |_status|
|
|
|
|
method.call(1)
|
2014-06-08 13:55:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an exception' do
|
|
|
|
expect { subject }.to raise_error(described_class::Error, 'Childprocess exited with nonzero exit status: 1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|