Class: RSpec::Conductor::RSpecSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/conductor/rspec_subscriber.rb

Overview

Technically this is a Formatter, as in RSpec Formatter, but that was too confusing, and there is another thing called formatter in this library. Hence, Subscriber.

Instance Method Summary collapse

Constructor Details

#initialize(socket, file, shutdown_check) ⇒ RSpecSubscriber

Returns a new instance of RSpecSubscriber.



13
14
15
16
17
# File 'lib/rspec/conductor/rspec_subscriber.rb', line 13

def initialize(socket, file, shutdown_check)
  @socket = socket
  @file = file
  @shutdown_check = shutdown_check
end

Instance Method Details

#example_failed(notification) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rspec/conductor/rspec_subscriber.rb', line 30

def example_failed(notification)
  ex = notification.example
  @socket.send_message(
    type: :example_failed,
    file: @file,
    description: ex.full_description,
    location: ex.location,
    run_time: ex.execution_result.run_time,
    exception_class: ex.execution_result.exception&.class&.name,
    message: ex.execution_result.exception&.message,
    backtrace: format_backtrace(ex.execution_result.exception&.backtrace, ex.)
  )
  @shutdown_check.call
end

#example_passed(notification) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/rspec/conductor/rspec_subscriber.rb', line 19

def example_passed(notification)
  @socket.send_message(
    type: :example_passed,
    file: @file,
    description: notification.example.full_description,
    location: notification.example.location,
    run_time: notification.example.execution_result.run_time
  )
  @shutdown_check.call
end

#example_pending(notification) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rspec/conductor/rspec_subscriber.rb', line 45

def example_pending(notification)
  ex = notification.example
  @socket.send_message(
    type: :example_pending,
    file: @file,
    description: ex.full_description,
    location: ex.location,
    pending_message: ex.execution_result.pending_message
  )
  @shutdown_check.call
end

#retry(ex) ⇒ Object

This one is invoked by rspec-retry, hence the slightly different api from example_* methods



58
59
60
61
62
63
64
65
66
67
# File 'lib/rspec/conductor/rspec_subscriber.rb', line 58

def retry(ex)
  @socket.send_message(
    type: :example_retried,
    description: ex.full_description,
    location: ex.location,
    exception_class: ex.exception&.class&.name,
    message: ex.exception&.message,
    backtrace: format_backtrace(ex.exception&.backtrace, ex.)
  )
end