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

Inherits:
ExampleNotification show all
Defined in:
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:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exampleRSpec::Core::Example

the current example

Returns:

154
155
156
# File 'lib/rspec/core/notifications.rb', line 154
def example
  @example
end

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

193
194
195
# File 'lib/rspec/core/notifications.rb', line 193
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

178
179
180
# File 'lib/rspec/core/notifications.rb', line 178
def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  @exception_presenter.colorized_message_lines(colorizer)
end

#descriptionString

Returns The example description.

Returns:

  • (String)

    The example description

163
164
165
# File 'lib/rspec/core/notifications.rb', line 163
def description
  @exception_presenter.description
end

#exceptionException

Returns The example failure.

Returns:

  • (Exception)

    The example failure

158
159
160
# File 'lib/rspec/core/notifications.rb', line 158
def exception
  @exception_presenter.exception
end

#formatted_backtraceArray<String>

Returns the failures formatted backtrace.

Returns:

  • (Array<String>)

    the examples backtrace lines

185
186
187
# File 'lib/rspec/core/notifications.rb', line 185
def formatted_backtrace
  @exception_presenter.formatted_backtrace
end

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

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

Returns:

  • (String)

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

199
200
201
# File 'lib/rspec/core/notifications.rb', line 199
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 The failure information fully formatted in the way that RSpec's built-in formatters emit, split by line.

Returns:

  • (Array<string>)

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

205
206
207
# File 'lib/rspec/core/notifications.rb', line 205
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

170
171
172
# File 'lib/rspec/core/notifications.rb', line 170
def message_lines
  @exception_presenter.message_lines
end