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.



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

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, policy: :killed) ⇒ Object



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

def self.score(results, policy: :killed)
  killing_statuses = policy == :separate ? %i[killed] : %i[killed timeout]
  scoring_statuses = killing_statuses + %i[survived]
  kills = results.count { |r| killing_statuses.include?(status_for(r)) }
  scored = results.count { |r| scoring_statuses.include?(status_for(r)) }
  return 0.0 if scored.zero?

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

.status_for(result) ⇒ Object



16
17
18
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 16

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

Instance Method Details

#generateObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 32

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

#interrupted?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mutation_tester/reporters/base_reporter.rb', line 28

def interrupted?
  @interrupted
end