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:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exampleRSpec::Core::Example

the current example



150
151
152
# File 'lib/rspec/core/notifications.rb', line 150

def example
  @example
end

Instance Method Details

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

Returns the failures colorized formatted backtrace.



191
192
193
194
195
# File 'lib/rspec/core/notifications.rb', line 191

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

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

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



174
175
176
177
178
# File 'lib/rspec/core/notifications.rb', line 174

def colorized_message_lines(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  add_shared_group_lines(failure_lines, colorizer).map do |line|
    colorizer.wrap line, message_color
  end
end

#descriptionString



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

def description
  example.full_description
end

#exceptionException



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

def exception
  example.execution_result.exception
end

#formatted_backtraceArray<String>

Returns the failures formatted backtrace.



183
184
185
# File 'lib/rspec/core/notifications.rb', line 183

def formatted_backtrace
  backtrace_formatter.format_backtrace(exception.backtrace, example.)
end

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



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

def fully_formatted(failure_number, colorizer=::RSpec::Core::Formatters::ConsoleCodes)
  "\n  #{failure_number}) #{description}\n#{formatted_message_and_backtrace(colorizer)}"
end

#message_linesArray<String>

Returns the message generated for this failure line by line.



166
167
168
# File 'lib/rspec/core/notifications.rb', line 166

def message_lines
  add_shared_group_lines(failure_lines, NullColorizer)
end