class Crispr::Runner
runs the test suite, and restores the original file afterward.
It temporarily replaces the file’s source with a mutated version,
Runner is responsible for executing tests against mutated code.
def self.run_mutation(path:, mutated_source:, test_path: nil, verbose: false)
-
(Boolean)
- true if the mutation was killed (test suite failed), false otherwise
Parameters:
-
test_path
(String, nil
) -- optional path to a specific test file to run -
mutated_source
(String
) -- the mutated version of the file's source code -
path
(String
) -- the path to the source file to mutate
def self.run_mutation(path:, mutated_source:, test_path: nil, verbose: false) original_source = File.read(path) begin File.write(path, mutated_source) test_cmd = test_path ? "bundle exec rspec #{test_path}" : "bundle exec rspec" test_cmd += " > /dev/null 2>&1" unless verbose system(test_cmd) # Use $? to check the exit status of the last system call killed = !$?.success? killed ensure File.write(path, original_source) end end