123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::Notifications::FailedExampleNotification

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ExampleNotification, Struct
Instance Chain:
self, ExampleNotification, Struct
Inherits: RSpec::Core::Notifications::ExampleNotification
Defined in: rspec-core/lib/rspec/core/notifications.rb

Overview

The ‘FailedExampleNotification` extends ExampleNotification with things useful for examples that have failure info – typically a failed or pending spec.

Examples:

def example_failed(notification)
  puts "Hey I failed :("
  puts "Here's my stack trace"
  puts notification.exception.backtrace.join("\n")
end

See Also:

Class Method Summary

Instance Attribute Summary

  • #example rw

    The ‘FailedExampleNotification` extends ExampleNotification with things useful for examples that have failure info – typically a failed or pending spec.

ExampleNotification - Inherited

#example

The ‘ExampleNotification` represents notifications sent by the reporter which contain information about the current (or soon to be) example.

Instance Method Summary

Constructor Details

.new(example, exception_presenter = Formatters::ExceptionPresenter::Factory.new(example).build) ⇒ FailedExampleNotification (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 213

def initialize(example, exception_presenter=Formatters::ExceptionPresenter::Factory.new(example).build)
  @exception_presenter = exception_presenter
  super(example)
end

Instance Attribute Details

#example (rw)

The ‘FailedExampleNotification` extends ExampleNotification with things useful for examples that have failure info – typically a failed or pending spec.

Examples:

def example_failed(notification)
  puts "Hey I failed :("
  puts "Here's my stack trace"
  puts notification.exception.backtrace.join("\n")
end

See Also:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 156

class FailedExampleNotification < ExampleNotification
public_class_method :new

# @return [Exception] The example failure
def exception
  @exception_presenter.exception
end

# @return [String] The example description
def description
  @exception_presenter.description
end

# Returns the message generated for this failure line by line.
#
# @return [Array<String>] The example failure message
def message_lines
  @exception_presenter.message_lines
end

# Returns the message generated for this failure colorized line by line.
#
# @param colorizer [#wrap] An object to colorize the message_lines by
# @return [Array<String>] The example failure message colorized
def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)

Instance Method Details

#colorized_formatted_backtrace(colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Array<String>

Returns the failures colorized formatted backtrace.

Parameters:

  • colorizer (#wrap) (defaults to: ::RSpec::Core::Formatters::ConsoleCodes)

    An object to colorize the message_lines by

Returns:

  • (Array<String>)

    the examples colorized backtrace lines

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 195

def colorized_formatted_backtrace(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  @exception_presenter.colorized_formatted_backtrace(colorizer)
end

#colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Array<String>

Returns the message generated for this failure colorized line by line.

Parameters:

  • colorizer (#wrap) (defaults to: ::RSpec::Core::Formatters::ConsoleCodes)

    An object to colorize the message_lines by

Returns:

  • (Array<String>)

    The example failure message colorized

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 180

def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  @exception_presenter.colorized_message_lines(colorizer)
end

#descriptionString

Returns:

  • (String)

    The example description

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 165

def description
  @exception_presenter.description
end

#exceptionException

Returns:

  • (Exception)

    The example failure

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 160

def exception
  @exception_presenter.exception
end

#formatted_backtraceArray<String>

Returns the failures formatted backtrace.

Returns:

  • (Array<String>)

    the examples backtrace lines

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 187

def formatted_backtrace
  @exception_presenter.formatted_backtrace
end

#fully_formatted(failure_number, colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ String

Returns:

  • (String)

    The failure information fully formatted in the way that RSpec’s built-in formatters emit.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 201

def fully_formatted(failure_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  @exception_presenter.fully_formatted(failure_number, colorizer)
end

#fully_formatted_lines(failure_number, colorizer = ::RSpec::Core::Formatters::ConsoleCodes) ⇒ Array<string>

Returns:

  • (Array<string>)

    The failure information fully formatted in the way that RSpec’s built-in formatters emit, split by line.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 207

def fully_formatted_lines(failure_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  @exception_presenter.fully_formatted_lines(failure_number, colorizer)
end

#message_linesArray<String>

Returns the message generated for this failure line by line.

Returns:

  • (Array<String>)

    The example failure message

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/notifications.rb', line 172

def message_lines
  @exception_presenter.message_lines
end