From 822ddd799ff66ade6c1fc22245f01eebb78a0417 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 8 Jun 2014 19:51:04 +0000 Subject: [PATCH] Make non mri specific specs pass under RBX --- lib/mutant/isolation.rb | 15 +++++++++++---- lib/mutant/subject/method/instance.rb | 2 +- spec/integration/mutant/corpus_spec.rb | 2 +- spec/unit/mutant/isolation_spec.rb | 11 +++++------ spec/unit/mutant/matcher/chain_spec.rb | 16 ++++------------ spec/unit/mutant/matcher/namespace_spec.rb | 2 +- spec/unit/mutant/warning_filter_spec.rb | 6 ++++++ 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/lib/mutant/isolation.rb b/lib/mutant/isolation.rb index 60129646..ee051dbe 100644 --- a/lib/mutant/isolation.rb +++ b/lib/mutant/isolation.rb @@ -18,9 +18,16 @@ module Mutant def self.call(&block) reader, writer = IO.pipe.each(&:binmode) - pid = fork do - reader.close - writer.write(Marshal.dump(block.call)) + pid = fork + + if pid.nil? + begin + reader.close + writer.write(Marshal.dump(block.call)) + Kernel.exit!(0) + ensure + Kernel.exit!(1) + end end writer.close @@ -40,7 +47,7 @@ module Mutant def self.read_result(reader, pid) begin data = Marshal.load(reader.read) - rescue ArgumentError + rescue ArgumentError, TypeError raise Error, 'Childprocess wrote un-unmarshallable data' end diff --git a/lib/mutant/subject/method/instance.rb b/lib/mutant/subject/method/instance.rb index 2d7ac2d0..c629c02c 100644 --- a/lib/mutant/subject/method/instance.rb +++ b/lib/mutant/subject/method/instance.rb @@ -32,7 +32,7 @@ module Mutant # def prepare expected_warnings = - if name.equal?(:initialize) + if RUBY_ENGINE.eql?('ruby') && name.equal?(:initialize) ["#{__FILE__}:#{__LINE__ + 5}: warning: undefining `initialize' may cause serious problems\n"] else [] diff --git a/spec/integration/mutant/corpus_spec.rb b/spec/integration/mutant/corpus_spec.rb index 71f841e9..87791fcc 100644 --- a/spec/integration/mutant/corpus_spec.rb +++ b/spec/integration/mutant/corpus_spec.rb @@ -10,7 +10,7 @@ describe 'Mutant on ruby corpus' do TMP = ROOT.join('tmp').freeze before do - pending 'Corpus test is deactivated on 1.9.3' if RUBY_VERSION.eql?('1.9.3') + skip 'Corpus test is deactivated on 1.9.3' if RUBY_VERSION.eql?('1.9.3') end MUTEX = Mutex.new diff --git a/spec/unit/mutant/isolation_spec.rb b/spec/unit/mutant/isolation_spec.rb index ac84ca8f..4780cfc9 100644 --- a/spec/unit/mutant/isolation_spec.rb +++ b/spec/unit/mutant/isolation_spec.rb @@ -28,7 +28,7 @@ describe Mutant::Isolation do let(:block) do lambda do redirect_stderr - $stderr # not mashallable, nothing written to pipe and raised exceptions in child + $stderr # not mashallable, nothing written to pipe and raises exception in child end end @@ -37,14 +37,13 @@ describe Mutant::Isolation do end end - context 'when block does return marshallable data, but process exits with nonzero exitstatus' do + context 'when block causes the child to exit nonzero' do let(:block) do lambda do - redirect_stderr - at_exit do - raise + method = Kernel.method(:exit!) + Kernel.define_singleton_method(:exit!) do |_status| + method.call(1) end - :foo end end diff --git a/spec/unit/mutant/matcher/chain_spec.rb b/spec/unit/mutant/matcher/chain_spec.rb index 27970548..a9999f6e 100644 --- a/spec/unit/mutant/matcher/chain_spec.rb +++ b/spec/unit/mutant/matcher/chain_spec.rb @@ -11,16 +11,12 @@ describe Mutant::Matcher::Chain do let(:matchers) { [matcher_a, matcher_b] } - let(:matcher_a) { double('Matcher A') } - let(:matcher_b) { double('Matcher B') } + let(:matcher_a) { [subject_a] } + let(:matcher_b) { [subject_b] } let(:subject_a) { double('Subject A') } let(:subject_b) { double('Subject B') } - before do - matcher_a.stub(:each).and_yield(subject_a).and_return(matcher_a) - matcher_b.stub(:each).and_yield(subject_b).and_return(matcher_b) - end # it_should_behave_like 'an #each method' context 'with no block' do @@ -28,12 +24,8 @@ describe Mutant::Matcher::Chain do it { should be_instance_of(to_enum.class) } - if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' - pending 'FIX RBX rspec? BUG HERE' - else - it 'yields the expected values' do - expect(subject.to_a).to eql(object.to_a) - end + it 'yields the expected values' do + expect(subject.to_a).to eql(object.to_a) end end diff --git a/spec/unit/mutant/matcher/namespace_spec.rb b/spec/unit/mutant/matcher/namespace_spec.rb index 49398cf3..1037c3f1 100644 --- a/spec/unit/mutant/matcher/namespace_spec.rb +++ b/spec/unit/mutant/matcher/namespace_spec.rb @@ -34,7 +34,7 @@ describe Mutant::Matcher::Namespace do it { should be_instance_of(to_enum.class) } if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' - pending 'FIX RBX rspec? BUG HERE' + skip 'FIX RBX rspec? BUG HERE' else it 'yields the expected values' do expect(subject.to_a).to eql(object.to_a) diff --git a/spec/unit/mutant/warning_filter_spec.rb b/spec/unit/mutant/warning_filter_spec.rb index 1c24fe2f..2f200c68 100644 --- a/spec/unit/mutant/warning_filter_spec.rb +++ b/spec/unit/mutant/warning_filter_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' describe Mutant::WarningFilter do + before do + if RUBY_ENGINE.eql?('rbx') + skip 'Disabled because expected warnings are from MRI' + end + end + let(:object) { described_class.new(target) } let(:target) do