Class: RSpec::Signal::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/signal/writer.rb

Overview

Puts artifacts on disk.

A run with no failures removes artifacts from previous runs, so an agent can never be handed a stale report that describes failures you already fixed.

Defined Under Namespace

Classes: Result

Constant Summary collapse

SIGNAL =
"signal.md"
JSON =
"signal.json"
FULL =
"full.txt"
MANAGED =
[SIGNAL, JSON, FULL].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Writer

Returns a new instance of Writer.



20
21
22
# File 'lib/rspec/signal/writer.rb', line 20

def initialize(config)
  @config = config
end

Instance Method Details

#dirObject



24
25
26
# File 'lib/rspec/signal/writer.rb', line 24

def dir
  @config.output_path
end

#relative(path) ⇒ Object

Relative to the project root when possible, because that is what you type and what an agent resolves.



44
45
46
47
# File 'lib/rspec/signal/writer.rb', line 44

def relative(path)
  root = "#{@config.root}/"
  path.start_with?(root) ? path[root.length..] : path
end

#write(report) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rspec/signal/writer.rb', line 28

def write(report)
  return clean if report.failures.empty? && report.errors_outside_examples.zero?

  FileUtils.mkdir_p(dir)
  write_gitignore

  markdown = Reporters::Markdown.new(report, @config).render
  written = [write_file(SIGNAL, markdown)]
  written.concat(optional_artifacts(report))

  stale = MANAGED - written.map { |path| File.basename(path) }
  Result.new(summary_path: File.join(dir, SIGNAL), written: written, cleaned: remove(stale))
end