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 failed specs.

Examples:

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

See Also:

Direct Known Subclasses

PendingExampleFixedNotification

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (RSpec::Core::Example) example

the current example

Returns:

142
143
144
# File 'lib/rspec/core/notifications.rb', line 142
def example
  @example
end

Instance Method Details

- (Array(String)) colorized_formatted_backtrace(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)

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

183
184
185
186
187
# File 'lib/rspec/core/notifications.rb', line 183
def colorized_formatted_backtrace(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
  formatted_backtrace.map do |backtrace_info|
    colorizer.wrap "# #{backtrace_info}", RSpec.configuration.detail_color
  end
end

- (Array(String)) colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)

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

166
167
168
169
170
# File 'lib/rspec/core/notifications.rb', line 166
def colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
  add_shared_group_line(failure_lines, colorizer).map do |line|
    colorizer.wrap line, RSpec.configuration.failure_color
  end
end

- (String) description

Returns The example description

Returns:

  • (String)

    The example description

151
152
153
# File 'lib/rspec/core/notifications.rb', line 151
def description
  example.full_description
end

- (Exception) exception

Returns The example failure

Returns:

  • (Exception)

    The example failure

146
147
148
# File 'lib/rspec/core/notifications.rb', line 146
def exception
  example.execution_result.exception
end

- (Array(String)) formatted_backtrace

Returns the failures formatted backtrace.

Returns:

  • (Array(String))

    the examples backtrace lines

175
176
177
# File 'lib/rspec/core/notifications.rb', line 175
def formatted_backtrace
  backtrace_formatter.format_backtrace(exception.backtrace, example.)
end

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

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.

191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/rspec/core/notifications.rb', line 191
def fully_formatted(failure_number, colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
  formatted = "\n  #{failure_number}) #{description}\n"
  colorized_message_lines(colorizer).each do |line|
    formatted << RSpec::Support::EncodedString.new("     #{line}\n", encoding_of(formatted))
  end
  colorized_formatted_backtrace(colorizer).each do |line|
    formatted << RSpec::Support::EncodedString.new("     #{line}\n", encoding_of(formatted))
  end
  formatted
end

- (Array(String)) message_lines

Returns the message generated for this failure line by line.

Returns:

  • (Array(String))

    The example failure message

158
159
160
# File 'lib/rspec/core/notifications.rb', line 158
def message_lines
  add_shared_group_line(failure_lines, NullColorizer)
end