Class: Croaky::RSpec::CroakyFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseTextFormatter
- Object
- RSpec::Core::Formatters::BaseTextFormatter
- Croaky::RSpec::CroakyFormatter
- 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
-
#io_stream ⇒ Object
readonly
Returns the value of attribute io_stream.
Instance Method Summary collapse
- #dump_failures(notification) ⇒ Object
- #example_failed(notification) ⇒ Object
- #example_passed(_notification) ⇒ Object
- #example_pending(_notification) ⇒ Object
- #example_started(_notification) ⇒ Object
-
#initialize(output, io_stream = ::Croaky::Builders.io_stream) ⇒ CroakyFormatter
constructor
A new instance of CroakyFormatter.
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_stream ⇒ Object (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
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/croaky/rspec/croaky_formatter.rb', line 53 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
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/croaky/rspec/croaky_formatter.rb', line 41 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
30 31 32 33 |
# File 'lib/croaky/rspec/croaky_formatter.rb', line 30 def example_passed(_notification) io_stream.restore_io output.print COLORIZER.wrap('.', :success) end |
#example_pending(_notification) ⇒ Object
35 36 37 38 |
# File 'lib/croaky/rspec/croaky_formatter.rb', line 35 def example_pending(_notification) io_stream.restore_io output.print COLORIZER.wrap('*', :pending) end |
#example_started(_notification) ⇒ Object
26 27 28 |
# File 'lib/croaky/rspec/croaky_formatter.rb', line 26 def example_started(_notification) io_stream.capture_io end |