Class: OnceoverFormatterParallel

Inherits:
OnceoverFormatter show all
Defined in:
lib/onceover/rspec/formatters.rb

Constant Summary

Constants inherited from OnceoverFormatter

OnceoverFormatter::COMPILATION_ERROR, OnceoverFormatter::ERROR_WITHOUT_LOCATION, OnceoverFormatter::ERROR_WITH_LOCATION

Instance Method Summary collapse

Methods inherited from OnceoverFormatter

#black, #blue, #bold, #calculate_relative_source, #class_name, #cyan, #extract_failure_data, #extract_failures, #green, #initialize, #longest_group, #magenta, #parse_errors, #red, #white, #yellow

Constructor Details

This class inherits a constructor from OnceoverFormatter

Instance Method Details

#dump_failures(notification) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/onceover/rspec/formatters.rb', line 260

def dump_failures notification
  # Create a random string
  require 'securerandom'
  random_string = SecureRandom.hex

  # Ensure that the folder exists
  FileUtils.mkdir_p "#{RSpec.configuration.onceover_tempdir}/parallel"

  # Dump the notification to a unique file
  File.open("#{RSpec.configuration.onceover_tempdir}/parallel/results-#{random_string}.yaml", "w") do |file|
    file.write(extract_failures(notification).to_yaml)
  end
end

#example_failed(notification) ⇒ Object



250
251
252
253
# File 'lib/onceover/rspec/formatters.rb', line 250

def example_failed notification
  @output << red('F')
  @output.flush
end

#example_group_started(notification) ⇒ Object



241
242
243
# File 'lib/onceover/rspec/formatters.rb', line 241

def example_group_started notification
  # Do nothing
end

#example_passed(notification) ⇒ Object



245
246
247
248
# File 'lib/onceover/rspec/formatters.rb', line 245

def example_passed notification
  @output << green('P')
  @output.flush
end

#example_pending(notification) ⇒ Object



255
256
257
258
# File 'lib/onceover/rspec/formatters.rb', line 255

def example_pending notification
  @output << yellow('?')
  @output.flush
end

#output_results(directory) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/onceover/rspec/formatters.rb', line 274

def output_results(directory)
  require 'rspec/core/example'
  # Read all yaml files
  results = {}
  files   = Dir["#{directory}/*.yaml"]

  # Merge data
  roles = files.reduce({}) do |errs, file|
    # Read all files and merge them
    errs.merge(YAML.load(File.read(file))) {|key, oldval, newval| [oldval, newval].flatten }# rubocop:disable Security/YAMLLoad
  end

  # Delete files from the disk
  files.each { |f| File.delete(f) }

  @output << "\n\n\n"

  # Output errors
  roles.each do |name, errors|
    @output << Onceover::Controlrepo.evaluate_template('error_summary.yaml.erb', binding)
  end
  @output << "\n"
end