Class: Spec::Runner::Formatter::QuickfixFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/spec/quickfix_formatter.rb

Constant Summary collapse

MULTI_LINE_ERRORS =

turn this on to output multiline error in quickfix. This kinda abuses quickfix but can provide the backtrace

false

Instance Method Summary collapse

Constructor Details

#initialize(options, output) ⇒ QuickfixFormatter

Returns a new instance of QuickfixFormatter.



9
10
11
12
13
14
15
# File 'lib/spec/quickfix_formatter.rb', line 9

def initialize(options, output)
  @options = options
  @output = output
  unless @output.is_a?(IO)
    @output = File.new(output, 'w')
  end
end

Instance Method Details

#example_failed(example, counter, failure) ⇒ Object

use with this errorformat set errorformat=%f:%l\ %n\ %m



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/spec/quickfix_formatter.rb', line 19

def example_failed(example, counter, failure)
  first_time = true

  failure.exception.backtrace.reverse.each do |frame|
    file, line, message = parse_backtrace(frame)
    message = failure.header if message.blank?

    if first_time and failure.exception.message.present?
      first_time = false
      message += failure.exception.message
    end

    @output.puts "%s:%d %d %s" % [file, line, counter, message]
    @output.flush

    MULTI_LINE_ERRORS or break
  end
end