Class: Rutema::Reporters::JSON

Inherits:
BlockReporter show all
Defined in:
lib/rutema/reporters/json.rb

Overview

Experimental reporter used to dump the data of a run on disk

The following configuration keys are used by Rutema::Reporters::JSON

filename - the filename to use to save the YAML dump. Default is 'rutema.results.json'

Constant Summary collapse

DEFAULT_FILENAME =

Default report filename

"rutema.results.json".freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration, dispatcher) ⇒ JSON

Returns a new instance of JSON.



17
18
19
20
# File 'lib/rutema/reporters/json.rb', line 17

def initialize(configuration, dispatcher)
  super
  @filename = configuration.reporters.fetch(self.class, {}).fetch("filename", DEFAULT_FILENAME)
end

Instance Method Details

#report(specs, states, errors) ⇒ Object

We get all the data from a test run in here.



23
24
25
26
27
28
29
30
31
# File 'lib/rutema/reporters/json.rb', line 23

def report(specs, states, errors)
  run_entry = {}
  run_entry["specs"] = specs.size
  run_entry["context"] = @configuration.context if @configuration&.context
  run_entry["errors"] = errors
  run_entry["states"] = states

  Rutema::Utilities.write_file(@filename, ::JSON.dump(run_entry))
end