Module: Mutineer::TestRunners::RSpec
- Defined in:
- lib/mutineer/test_runners/rspec.rb
Overview
Child-process-only RSpec runner, mirroring MinitestIntegration's contract: run the given spec files and return 0 (all passed) / 1 (any failure).
rspec-core is required LAZILY here, never at load time, so Mutineer keeps zero runtime gem deps; a missing rspec raises a clear Mutineer error.
No rescue around the run itself: Isolation.run's fork block is the single
exception boundary (any exception there -> exit 2), keeping the 0/1 contract.
Class Method Summary collapse
- .require_rspec! ⇒ Object
-
.run(spec_files) ⇒ Object
spec_filesis one path or an Array of paths (coverage selection passes the covering subset).
Class Method Details
.require_rspec! ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/mutineer/test_runners/rspec.rb', line 51 def self.require_rspec! require "rspec/core" rescue LoadError raise Mutineer::FrameworkUnavailable, "framework 'rspec' requested but rspec is not available; " \ "add rspec to the project under test (its bundle), then retry" end |
.run(spec_files) ⇒ Object
spec_files is one path or an Array of paths (coverage selection passes
the covering subset). All are loaded+run in a single RSpec invocation.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mutineer/test_runners/rspec.rb', line 22 def self.run(spec_files) require_rspec! # rspec/autorun (if a spec_helper required it) installs an at_exit run; # neutralise it like Minitest.autorun so it never double-fires. ::RSpec::Core::Runner.disable_autorun! # Drop any RSpec world/configuration inherited across runs in one process # (e.g. successive forks of a booted parent) so examples never accumulate. ::RSpec.reset # Silence RSpec's formatter output (and any stray puts/deprecations) so it # never pollutes Mutineer's report streams. The formatter writes to the # passed IO; $stdout/$stderr are redirected to catch everything else. sink = StringIO.new orig_out = $stdout orig_err = $stderr $stdout = sink $stderr = sink begin status = ::RSpec::Core::Runner.run(["--no-color", *Array(spec_files)], sink, sink) ensure $stdout = orig_out $stderr = orig_err end status.zero? ? 0 : 1 end |