Class: ActiveMutator::Worker
- Inherits:
-
Object
- Object
- ActiveMutator::Worker
- Defined in:
- lib/active_mutator/worker.rb
Overview
Runs INSIDE a fork. Order is critical: RSpec's setup phase loads the spec files, whose spec_helper/rails_helper loads the application — only THEN can the mutation be inserted over the loaded original. Insert-first would NameError on any project not preloaded in the parent (all non-Rails projects), and loading app code after insertion would silently restore the original method.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mutation, example_ids, writer) ⇒ Worker
constructor
A new instance of Worker.
- #run ⇒ Object
Constructor Details
#initialize(mutation, example_ids, writer) ⇒ Worker
Returns a new instance of Worker.
16 17 18 19 20 |
# File 'lib/active_mutator/worker.rb', line 16 def initialize(mutation, example_ids, writer) @mutation = mutation @example_ids = example_ids @writer = writer end |
Class Method Details
.run(mutation, example_ids, writer) ⇒ Object
12 13 14 |
# File 'lib/active_mutator/worker.rb', line 12 def self.run(mutation, example_ids, writer) new(mutation, example_ids, writer).run end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_mutator/worker.rb', line 22 def run require "rspec/core" devnull = File.open(File::NULL, "w") runner = RSpec::Core::Runner.new(RSpec::Core::ConfigurationOptions.new(@example_ids)) runner.setup(devnull, devnull) # loads spec files -> loads the app Inserter.new.insert(@mutation) # now the target constant exists after_fork_hygiene code = runner.run_specs(covering_groups) emit(code.zero? ? "survived" : "killed") rescue StandardError, ScriptError => e emit("error", details: "#{e.class}: #{e.}") end |