Class: Croaky::RSpec::CroakyFormatter

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/croaky/rspec/croaky_formatter.rb

Overview

Croaky formatter

Constant Summary collapse

NOTIFICATIONS =
%i[start example_started example_passed example_pending example_failed].freeze
COLORIZER =
::RSpec::Core::Formatters::ConsoleCodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, io_stream = ::Croaky::Builders.io_stream) ⇒ CroakyFormatter

Returns a new instance of CroakyFormatter.



20
21
22
23
24
# File 'lib/croaky/rspec/croaky_formatter.rb', line 20

def initialize(output, io_stream = ::Croaky::Builders.io_stream)
  super(output)

  @io_stream = io_stream
end

Instance Attribute Details

#io_streamObject (readonly)

Returns the value of attribute io_stream.



18
19
20
# File 'lib/croaky/rspec/croaky_formatter.rb', line 18

def io_stream
  @io_stream
end

Instance Method Details

#dump_failures(notification) ⇒ Object

Parameters:

  • notification (RSpec::Core::Notifications::ExamplesNotification)


59
60
61
62
63
64
65
66
67
68
# File 'lib/croaky/rspec/croaky_formatter.rb', line 59

def dump_failures(notification)
  return if notification.failure_notifications.empty?

  output.puts
  output.puts 'Failures:'
  notification.failure_notifications.each_with_index do |failure, index|
    output.puts failure.fully_formatted(index.next, COLORIZER)
    output.puts failure.example.captured_io
  end
end

#example_failed(notification) ⇒ Object

Parameters:

  • notification (RSpec::Core::Notifications::FailedExampleNotification)


47
48
49
50
51
52
53
54
55
56
# File 'lib/croaky/rspec/croaky_formatter.rb', line 47

def example_failed(notification)
  io_stream.restore_io

  class << notification.example
    attr_accessor :captured_io
  end

  notification.example.captured_io = io_stream.read_captured_io
  output.print COLORIZER.wrap('F', :failure)
end

#example_passed(_notification) ⇒ Object



36
37
38
39
# File 'lib/croaky/rspec/croaky_formatter.rb', line 36

def example_passed(_notification)
  io_stream.restore_io
  output.print COLORIZER.wrap('.', :success)
end

#example_pending(_notification) ⇒ Object



41
42
43
44
# File 'lib/croaky/rspec/croaky_formatter.rb', line 41

def example_pending(_notification)
  io_stream.restore_io
  output.print COLORIZER.wrap('*', :pending)
end

#example_started(_notification) ⇒ Object



32
33
34
# File 'lib/croaky/rspec/croaky_formatter.rb', line 32

def example_started(_notification)
  io_stream.capture_io
end

#start(notification) ⇒ Object



26
27
28
29
30
# File 'lib/croaky/rspec/croaky_formatter.rb', line 26

def start(notification)
  super(notification)

  io_stream.capture_io
end