diff --git a/config/flay.yml b/config/flay.yml index 1f473d54..2301bdc6 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 1039 +total_score: 1053 diff --git a/lib/mutant/result.rb b/lib/mutant/result.rb index be91f4bf..5b49227b 100644 --- a/lib/mutant/result.rb +++ b/lib/mutant/result.rb @@ -54,6 +54,18 @@ module Mutant end memoize name end + + # Compute result tracking runtime + # + # @return [Result] + # + # @api private + # + def compute + start = Time.now + new(yield.merge(runtime: Time.now - start)) + end + end # ClassMethods # Test if operation is failing diff --git a/lib/mutant/runner.rb b/lib/mutant/runner.rb index 937244d1..0f228c02 100644 --- a/lib/mutant/runner.rb +++ b/lib/mutant/runner.rb @@ -18,13 +18,12 @@ module Mutant progress(env) - start = Time.now - - @result = Result::Env.new( - env: env, - subject_results: visit_collection(env.subjects, &method(:run_subject)), - runtime: Time.now - start - ).tap(&config.reporter.method(:report)) + @result = Result::Env.compute do + { + env: env, + subject_results: visit_collection(env.subjects, &method(:run_subject)) + } + end end # Return result @@ -44,11 +43,12 @@ module Mutant # @api private # def run_subject(subject) - Result::Subject.new( - subject: subject, - mutation_results: visit_collection(subject.mutations, &method(:run_mutation)), - runtime: nil - ) + Result::Subject.compute do + { + subject: subject, + mutation_results: visit_collection(subject.mutations, &method(:run_mutation)) + } + end end # Run mutation @@ -60,15 +60,12 @@ module Mutant # @api private # def run_mutation(mutation) - start = Time.now - - test_results = kill_mutation(mutation) - - Result::Mutation.new( - mutation: mutation, - runtime: Time.now - start, - test_results: test_results - ) + Result::Mutation.compute do + { + mutation: mutation, + test_results: kill_mutation(mutation) + } + end end # Kill mutation