Class: MutationTester::Reporters::BaseReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/mutation_tester/reporters/base_reporter.rb

Direct Known Subclasses

ConsoleReporter, HtmlReporter, JsonReporter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results, source_file, spec_file, config, interrupted: false) ⇒ BaseReporter

Returns a new instance of BaseReporter.



18
19
20
21
22
23
24
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 18

def initialize(results, source_file, spec_file, config, interrupted: false)
  @results = results
  @source_file = source_file
  @spec_file = spec_file
  @config = config
  @interrupted = interrupted
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 4

def config
  @config
end

#resultsObject (readonly)

Returns the value of attribute results.



4
5
6
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 4

def results
  @results
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



4
5
6
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 4

def source_file
  @source_file
end

#spec_fileObject (readonly)

Returns the value of attribute spec_file.



4
5
6
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 4

def spec_file
  @spec_file
end

Class Method Details

.score(results) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 6

def self.score(results)
  effective_killed = results.count { |r| %i[killed timeout].include?(status_for(r)) }
  scored = results.count { |r| %i[killed timeout survived].include?(status_for(r)) }
  return 0.0 if scored.zero?

  (effective_killed.to_f / scored * 100).round(2)
end

.status_for(result) ⇒ Object



14
15
16
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 14

def self.status_for(result)
  result[:status] || (result[:killed] ? :killed : :survived)
end

Instance Method Details

#generateObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 30

def generate
  raise NotImplementedError, 'Subclasses must implement #generate'
end

#interrupted?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 26

def interrupted?
  @interrupted
end