Class: Ruber::RSpec::Version2Formatter

Inherits:
BaseFormatter show all
Defined in:
plugins/rspec/ruber_rspec_formatter.rb

Constant Summary

Constants inherited from BaseFormatter

ENDING_DELIMITER, STARTING_DELIMITER

Instance Method Summary (collapse)

Methods inherited from BaseFormatter

#dump_failure, #dump_failures, #dump_pending, #dump_summary, #example_passed, #example_started, #start, #write_data

Instance Method Details

- (nil) example_failed(ex)

TODO:

add an entry contaning the code which caused the error (obtained using the

Method called by RSpec after an example has been completed and failed

It writes to the output a YAML dump of a hash with the following entries:

  • :type: :failure
  • :description: the name of the failed example, made of the name of the example group and the description of the example itself
  • :exception: the name of the exception class which caused the failure
  • :message: the error message contained in the exception which caused the failure
  • :location: a string with the location (file name and line number) where the failure happened
  • :backtrace: a string containing the entries of the exception’s backtrace, joined by newlines read_failed_line method defined in RSpec::Core::Formatters::BaseFormatter).

Parameters:

  • ex (RSpec::Core::Example)

    the failed example

Returns:

  • (nil)


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 270

def example_failed ex
  super
  hash = {}
  hash[:type] = :failure
  hash[:description] = ex.[:full_description]
  # It seems that rspec up tp 2.2 uses :exception_encountered, while from
  # 2.3 it uses :exception. This should work for both
  exception = ex.[:execution_result][:exception]
  exception ||= ex.[:execution_result][:exception_encountered]
  hash[:exception] = exception.class.name
  hash[:message] = exception.message
  hash[:location] = ex.[:location]
  hash[:backtrace] =  format_backtrace(exception.backtrace, ex).join "\n"
  write_data hash
end

- (nil) example_pending(ex)

Method called by RSpec after a pending example has been executed

It writes to the output a YAML dump of a hash with the following entries:

  • :type: :pending
  • :description: the name of the pending example, made of the name of the example group and the description of the example itself
  • :message: the message produced by pending
  • :location: a string with the location (file name and line number) of pending example

Parameters:

  • ex (RSpec::Core::Example)

    the pending example

Returns:

  • (nil)


299
300
301
302
303
304
305
306
307
# File 'plugins/rspec/ruber_rspec_formatter.rb', line 299

def example_pending ex
  super
  hash = {}
  hash[:type] = :pending
  hash[:description] = ex.[:full_description]
  hash[:message] = ex.[:execution_result][:pending_message]
  hash[:location] = ex.[:location]
  write_data hash
end