<commit_before>require 'spec_helper'

describe Mutant::Isolation do
  describe '.isolate' do
    let(:object) { described_class }

    before do
      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
      if ENV['COVERAGE']
        skip 'Simplecov inferences with these tests, skipping'
      end
    end

    let(:expected_return) { :foo }

    subject { object.call(&block) }

    def redirect_stderr
      $stderr = File.open('/dev/null')
    end

    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

    context 'when block does return marshallable data' do
      let(:block) do
        lambda do
          redirect_stderr
          $stderr # not mashallable, nothing written to pipe and raises exception in child
        end
      end

      it 'raises an exception' do
        expect { subject }.to raise_error(described_class::Error, 'Childprocess wrote un-unmarshallable data')
      end
    end

    context 'when block causes the child to exit nonzero' do
      let(:block) do
        lambda do
          method = Kernel.method(:exit!)
          Kernel.define_singleton_method(:exit!) do |_status|
            method.call(1)
          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<commit_msg>Better rspec context name<commit_after>require 'spec_helper'

describe Mutant::Isolation do
  describe '.isolate' do
    let(:object) { described_class }

    before do
      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
      if ENV['COVERAGE']
        skip 'Simplecov inferences with these tests, skipping'
      end
    end

    let(:expected_return) { :foo }

    subject { object.call(&block) }

    def redirect_stderr
      $stderr = File.open('/dev/null')
    end

    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

    context 'when block does NOT return marshallable data' do
      let(:block) do
        lambda do
          redirect_stderr
          $stderr # not mashallable, nothing written to pipe and raises exception in child
        end
      end

      it 'raises an exception' do
        expect { subject }.to raise_error(described_class::Error, 'Childprocess wrote un-unmarshallable data')
      end
    end

    context 'when block causes the child to exit nonzero' do
      let(:block) do
        lambda do
          method = Kernel.method(:exit!)
          Kernel.define_singleton_method(:exit!) do |_status|
            method.call(1)
          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
{'fraction_non_alphanumeric': 0.07405177603853101, 'fraction_numerical': 0.00481637567730283, 'mean_word_length': 2.2999006951340615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3811881', 'n_tokens_mistral': 973, 'n_tokens_neox': 915, 'n_words': 317}