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)
-
(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) original_source = File.read(path) begin File.write(path, mutated_source) test_cmd = test_path ? "bundle exec rspec #{test_path}" : "bundle exec rspec" stdout, stderr, status = Open3.capture3(test_cmd) killed = !status.success? puts stdout unless status.success? puts stderr unless status.success? killed ensure File.write(path, original_source) end end