Class: RSpec::Abq::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/abq/formatter.rb

Overview

Formatters are used to format RSpec test results. In our case, we’re using it to report test results to the abq socket.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_output) ⇒ Formatter

we don’t use the output IO for this formatter (we report everything via the socket)



16
17
# File 'lib/rspec/abq/formatter.rb', line 16

def initialize(_output) # rubocop:disable Lint/RedundantInitialize
end

Class Method Details

.abq_result(example) ⇒ Object

takes a completed example and creates a abq-compatible test result



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rspec/abq/formatter.rb', line 28

def self.abq_result(example)
  execution_result = example.execution_result
  tags, meta = Manifest.(example.)
  test_result = {
    status: status(example),
    id: example.id,
    display_name: example.[:full_description],
    output: if execution_result.exception
              RSpec::Core::Formatters::ExceptionPresenter
                .new(execution_result.exception, example)
                .fully_formatted(1)
            end,
    runtime: (execution_result.run_time * 1_000_000_000).round,
    tags: tags,
    meta: meta,
    location: {
      file: example.[:file_path],
      line: example.[:line_number]
    },
    started_at: execution_result.started_at.utc.iso8601(6), # anything higher-prescision just yielded 0s
    finished_at: execution_result.finished_at.utc.iso8601(6),
    lineage: RSpec::Core::Metadata.ascend(example.).map { |meta| meta[:description] }.reverse
  }

  past_rspec_retry_attempts = rspec_retry_attempts(example)
  if past_rspec_retry_attempts
    test_result[:past_attempts] = past_rspec_retry_attempts
  end

  {test_result: test_result}
end

Instance Method Details

#example_passed(notification) ⇒ Object Also known as: example_pending, example_failed

called when an example is completed (this method is aliased to example_pending and example_failed)



20
21
22
# File 'lib/rspec/abq/formatter.rb', line 20

def example_passed(notification)
  Abq.protocol_write(Formatter.abq_result(notification.example))
end